Skip to main content

oak_php/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5/// PHP AST root node.
6#[derive(Debug, Clone, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct PhpRoot {
9    /// Top-level items in the PHP file.
10    pub items: Vec<PhpItem>,
11}
12
13/// PHP top-level items.
14#[derive(Debug, Clone, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub enum PhpItem {
17    /// Opening tag (`<?php`).
18    OpenTag,
19    /// Closing tag (`?>`).
20    CloseTag,
21    /// A PHP statement.
22    Statement(PhpStatement),
23    /// A function declaration.
24    Function(PhpFunction),
25    /// A class declaration.
26    Class(PhpClass),
27    /// An interface declaration.
28    Interface(PhpInterface),
29    /// A trait declaration.
30    Trait(PhpTrait),
31    /// A namespace declaration.
32    Namespace(PhpNamespace),
33    /// A use statement for importing symbols.
34    Use(PhpUse),
35}
36
37/// PHP statements.
38#[derive(Debug, Clone, PartialEq)]
39#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40pub enum PhpStatement {
41    /// An expression statement.
42    Expression(PhpExpression),
43    /// An `if` statement.
44    If(PhpIf),
45    /// A `while` loop.
46    While(PhpWhile),
47    /// A `for` loop.
48    For(PhpFor),
49    /// A `foreach` loop.
50    Foreach(PhpForeach),
51    /// A `switch` statement.
52    Switch(PhpSwitch),
53    /// A `try-catch-finally` block.
54    Try(PhpTry),
55    /// A `return` statement.
56    Return(Option<PhpExpression>),
57    /// A `break` statement.
58    Break(Option<PhpExpression>),
59    /// A `continue` statement.
60    Continue(Option<PhpExpression>),
61    /// An `echo` statement.
62    Echo(Vec<PhpExpression>),
63    /// A `print` statement.
64    Print(PhpExpression),
65    /// A `global` variable declaration.
66    Global(Vec<String>),
67    /// A `static` variable declaration.
68    Static(Vec<PhpVariable>),
69    /// An `unset` statement.
70    Unset(Vec<PhpExpression>),
71    /// A `declare` statement.
72    Declare(Vec<PhpDeclareItem>),
73    /// A block of statements enclosed in braces.
74    Block(Vec<PhpStatement>),
75}
76
77/// PHP expressions.
78#[derive(Debug, Clone, PartialEq)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub enum PhpExpression {
81    /// A literal value.
82    Literal(PhpLiteral),
83    /// A variable.
84    Variable(PhpVariable),
85    /// An array creation.
86    Array(Vec<PhpArrayElement>),
87    /// A function call.
88    FunctionCall(PhpFunctionCall),
89    /// A method call.
90    MethodCall(PhpMethodCall),
91    /// A property access.
92    PropertyAccess(PhpPropertyAccess),
93    /// An array element access.
94    ArrayAccess(PhpArrayAccess),
95    /// An assignment operation.
96    Assignment(PhpAssignment),
97    /// A binary operation.
98    BinaryOp(PhpBinaryOp),
99    /// A unary operation.
100    UnaryOp(PhpUnaryOp),
101    /// A ternary operation.
102    TernaryOp(PhpTernaryOp),
103    /// A type cast.
104    Cast(PhpCast),
105    /// An object instantiation.
106    New(PhpNew),
107    /// An object clone operation.
108    Clone(Box<PhpExpression>),
109    /// An `instanceof` check.
110    Instanceof(PhpInstanceof),
111    /// An `include` or `include_once` statement.
112    Include(PhpInclude),
113    /// A `require` or `require_once` statement.
114    Require(PhpRequire),
115    /// An `eval` call.
116    Eval(Box<PhpExpression>),
117    /// An `exit` or `die` call.
118    Exit(Option<Box<PhpExpression>>),
119    /// An `empty` check.
120    Empty(Box<PhpExpression>),
121    /// An `isset` check.
122    Isset(Vec<PhpExpression>),
123    /// A `list` or short array assignment.
124    List(Vec<Option<PhpExpression>>),
125    /// A `yield` expression for generators.
126    Yield(PhpYield),
127}
128
129/// PHP literals.
130#[derive(Debug, Clone, PartialEq)]
131#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
132pub enum PhpLiteral {
133    /// A string literal.
134    String(String),
135    /// A numeric literal.
136    Number(String),
137    /// A boolean literal.
138    Boolean(bool),
139    /// The `null` literal.
140    Null,
141}
142
143/// PHP variables.
144#[derive(Debug, Clone, PartialEq)]
145#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
146pub struct PhpVariable {
147    /// The name of the variable (including the `$` prefix).
148    pub name: String,
149}
150
151/// PHP array elements.
152#[derive(Debug, Clone, PartialEq)]
153#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
154pub struct PhpArrayElement {
155    /// Optional key for the array element.
156    pub key: Option<PhpExpression>,
157    /// The value of the array element.
158    pub value: PhpExpression,
159}
160
161/// PHP function call
162#[derive(Debug, Clone, PartialEq)]
163#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
164pub struct PhpFunctionCall {
165    /// Function name or expression.
166    pub name: Box<PhpExpression>,
167    /// Function arguments.
168    pub arguments: Vec<PhpExpression>,
169}
170
171/// PHP method call
172#[derive(Debug, Clone, PartialEq)]
173#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
174pub struct PhpMethodCall {
175    /// Object expression.
176    pub object: Box<PhpExpression>,
177    /// Method name.
178    pub method: String,
179    /// Method arguments.
180    pub arguments: Vec<PhpExpression>,
181}
182
183/// PHP property access
184#[derive(Debug, Clone, PartialEq)]
185#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
186pub struct PhpPropertyAccess {
187    /// Object expression.
188    pub object: Box<PhpExpression>,
189    /// Property name.
190    pub property: String,
191}
192
193/// PHP array access
194#[derive(Debug, Clone, PartialEq)]
195#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
196pub struct PhpArrayAccess {
197    /// Array expression.
198    pub array: Box<PhpExpression>,
199    /// Index expression.
200    pub index: Box<PhpExpression>,
201}
202
203/// PHP assignment
204#[derive(Debug, Clone, PartialEq)]
205#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
206pub struct PhpAssignment {
207    /// Left-hand side expression.
208    pub left: Box<PhpExpression>,
209    /// Assignment operator.
210    pub operator: PhpAssignmentOp,
211    /// Right-hand side expression.
212    pub right: Box<PhpExpression>,
213}
214
215/// PHP assignment operators.
216#[derive(Debug, Clone, PartialEq)]
217#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
218pub enum PhpAssignmentOp {
219    /// Standard assignment (`=`).
220    Assign,
221    /// Addition assignment (`+=`).
222    PlusAssign,
223    /// Subtraction assignment (`-=`).
224    MinusAssign,
225    /// Multiplication assignment (`*=`).
226    MultiplyAssign,
227    /// Division assignment (`/=`).
228    DivideAssign,
229    /// Modulo assignment (`%=`).
230    ModuloAssign,
231    /// Power assignment (`**=`).
232    PowerAssign,
233    /// Concatenation assignment (`.=`).
234    ConcatAssign,
235    /// Bitwise AND assignment (`&=`).
236    BitwiseAndAssign,
237    /// Bitwise OR assignment (`|=`).
238    BitwiseOrAssign,
239    /// Bitwise XOR assignment (`^=`).
240    BitwiseXorAssign,
241    /// Left shift assignment (`<<=`).
242    LeftShiftAssign,
243    /// Right shift assignment (`>>=`).
244    RightShiftAssign,
245    /// Null coalesce assignment (`??=`).
246    NullCoalesceAssign,
247}
248
249/// PHP binary operations.
250#[derive(Debug, Clone, PartialEq)]
251#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
252pub struct PhpBinaryOp {
253    /// Left operand.
254    pub left: Box<PhpExpression>,
255    /// Binary operator.
256    pub operator: PhpBinaryOperator,
257    /// Right operand.
258    pub right: Box<PhpExpression>,
259}
260
261/// PHP binary operators.
262#[derive(Debug, Clone, PartialEq)]
263#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
264pub enum PhpBinaryOperator {
265    /// Addition (`+`).
266    Plus,
267    /// Subtraction (`-`).
268    Minus,
269    /// Multiplication (`*`).
270    Multiply,
271    /// Division (`/`).
272    Divide,
273    /// Modulo (`%`).
274    Modulo,
275    /// Power (`**`).
276    Power,
277    /// Concatenation (`.`).
278    Concat,
279    /// Equality (`==`).
280    Equal,
281    /// Inequality (`!=`).
282    NotEqual,
283    /// Identity (`===`).
284    Identical,
285    /// Non-identity (`!==`).
286    NotIdentical,
287    /// Less than (`<`).
288    Less,
289    /// Less than or equal to (`<=`).
290    LessEqual,
291    /// Greater than (`>`).
292    Greater,
293    /// Greater than or equal to (`>=`).
294    GreaterEqual,
295    /// Spaceship operator (`<=>`).
296    Spaceship,
297    /// Logical AND (`&&` or `and`).
298    LogicalAnd,
299    /// Logical OR (`||` or `or`).
300    LogicalOr,
301    /// Logical XOR (`xor`).
302    LogicalXor,
303    /// Bitwise AND (`&`).
304    BitwiseAnd,
305    /// Bitwise OR (`|`).
306    BitwiseOr,
307    /// Bitwise XOR (`^`).
308    BitwiseXor,
309    /// Left shift (`<<`).
310    LeftShift,
311    /// Right shift (`>>`).
312    RightShift,
313    /// Null coalesce (`??`).
314    NullCoalesce,
315}
316
317/// PHP unary operations.
318#[derive(Debug, Clone, PartialEq)]
319#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
320pub struct PhpUnaryOp {
321    /// Unary operator.
322    pub operator: PhpUnaryOperator,
323    /// Operand.
324    pub operand: Box<PhpExpression>,
325}
326
327/// PHP unary operators.
328#[derive(Debug, Clone, PartialEq)]
329#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
330pub enum PhpUnaryOperator {
331    /// Unary plus (`+`).
332    Plus,
333    /// Unary minus (`-`).
334    Minus,
335    /// Logical NOT (`!`).
336    LogicalNot,
337    /// Bitwise NOT (`~`).
338    BitwiseNot,
339    /// Pre-increment (`++$a`).
340    PreIncrement,
341    /// Post-increment (`$a++`).
342    PostIncrement,
343    /// Pre-decrement (`--$a`).
344    PreDecrement,
345    /// Post-decrement (`$a--`).
346    PostDecrement,
347    /// Error suppression (`@`).
348    ErrorSuppression,
349}
350
351/// PHP ternary operations.
352#[derive(Debug, Clone, PartialEq)]
353#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
354pub struct PhpTernaryOp {
355    /// Condition expression.
356    pub condition: Box<PhpExpression>,
357    /// Expression for true branch (optional for shorthand `?:`).
358    pub true_expr: Option<Box<PhpExpression>>,
359    /// Expression for false branch.
360    pub false_expr: Box<PhpExpression>,
361}
362
363/// PHP type casts.
364#[derive(Debug, Clone, PartialEq)]
365#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
366pub struct PhpCast {
367    /// Target type for the cast.
368    pub cast_type: PhpCastType,
369    /// Expression to be cast.
370    pub expression: Box<PhpExpression>,
371}
372
373/// PHP cast types.
374#[derive(Debug, Clone, PartialEq)]
375#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
376pub enum PhpCastType {
377    /// Cast to integer (`(int)`).
378    Int,
379    /// Cast to float (`(float)`).
380    Float,
381    /// Cast to string (`(string)`).
382    String,
383    /// Cast to boolean (`(bool)`).
384    Bool,
385    /// Cast to array (`(array)`).
386    Array,
387    /// Cast to object (`(object)`).
388    Object,
389    /// Cast to unset (`(unset)`).
390    Unset,
391}
392
393/// PHP `new` expression.
394#[derive(Debug, Clone, PartialEq)]
395#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
396pub struct PhpNew {
397    /// Class name or expression.
398    pub class: Box<PhpExpression>,
399    /// Constructor arguments.
400    pub arguments: Vec<PhpExpression>,
401}
402
403/// PHP `instanceof` expression.
404#[derive(Debug, Clone, PartialEq)]
405#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
406pub struct PhpInstanceof {
407    /// Expression to check.
408    pub expression: Box<PhpExpression>,
409    /// Class name or expression.
410    pub class: Box<PhpExpression>,
411}
412
413/// PHP `include` expression.
414#[derive(Debug, Clone, PartialEq)]
415#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
416pub struct PhpInclude {
417    /// Whether it is `include_once`.
418    pub once: bool,
419    /// Path to the file.
420    pub path: Box<PhpExpression>,
421}
422
423/// PHP `require` expression.
424#[derive(Debug, Clone, PartialEq)]
425#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
426pub struct PhpRequire {
427    /// Whether it is `require_once`.
428    pub once: bool,
429    /// Path to the file.
430    pub path: Box<PhpExpression>,
431}
432
433/// PHP `yield` expression.
434#[derive(Debug, Clone, PartialEq)]
435#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
436pub struct PhpYield {
437    /// Optional key for yield (e.g., `yield $key => $value`).
438    pub key: Option<Box<PhpExpression>>,
439    /// Optional value for yield.
440    pub value: Option<Box<PhpExpression>>,
441    /// Whether it is a `yield from` expression.
442    pub from: bool,
443}
444
445/// PHP `if` statement.
446#[derive(Debug, Clone, PartialEq)]
447#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
448pub struct PhpIf {
449    /// Condition expression.
450    pub condition: Box<PhpExpression>,
451    /// The `then` block.
452    pub then_stmt: Box<PhpStatement>,
453    /// Any `elseif` blocks.
454    pub elseif_stmts: Vec<PhpElseif>,
455    /// Optional `else` block.
456    pub else_stmt: Option<Box<PhpStatement>>,
457}
458
459/// PHP `elseif` statement.
460#[derive(Debug, Clone, PartialEq)]
461#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
462pub struct PhpElseif {
463    /// Condition expression.
464    pub condition: Box<PhpExpression>,
465    /// The `elseif` block.
466    pub statement: Box<PhpStatement>,
467}
468
469/// PHP `while` loop.
470#[derive(Debug, Clone, PartialEq)]
471#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
472pub struct PhpWhile {
473    /// Loop condition.
474    pub condition: Box<PhpExpression>,
475    /// Loop body.
476    pub statement: Box<PhpStatement>,
477}
478
479/// PHP `for` loop.
480#[derive(Debug, Clone, PartialEq)]
481#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
482pub struct PhpFor {
483    /// Loop initialization expressions.
484    pub init: Vec<PhpExpression>,
485    /// Loop conditions.
486    pub condition: Vec<PhpExpression>,
487    /// Loop update expressions.
488    pub update: Vec<PhpExpression>,
489    /// Loop body.
490    pub statement: Box<PhpStatement>,
491}
492
493/// PHP `foreach` loop.
494#[derive(Debug, Clone, PartialEq)]
495#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
496pub struct PhpForeach {
497    /// Iterable expression.
498    pub iterable: Box<PhpExpression>,
499    /// Optional key variable.
500    pub key: Option<Box<PhpExpression>>,
501    /// Value variable.
502    pub value: Box<PhpExpression>,
503    /// Loop body.
504    pub statement: Box<PhpStatement>,
505}
506
507/// PHP `switch` statement.
508#[derive(Debug, Clone, PartialEq)]
509#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
510pub struct PhpSwitch {
511    /// Expression to switch on.
512    pub expression: Box<PhpExpression>,
513    /// Switch cases.
514    pub cases: Vec<PhpCase>,
515}
516
517/// PHP `case` statement.
518#[derive(Debug, Clone, PartialEq)]
519#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
520pub struct PhpCase {
521    /// Case value (None for the `default` case).
522    pub value: Option<Box<PhpExpression>>,
523    /// Statements within the case.
524    pub statements: Vec<PhpStatement>,
525}
526
527/// PHP `try-catch-finally` block.
528#[derive(Debug, Clone, PartialEq)]
529#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
530pub struct PhpTry {
531    /// The `try` block.
532    pub statement: Box<PhpStatement>,
533    /// Catch clauses.
534    pub catches: Vec<PhpCatch>,
535    /// Optional `finally` block.
536    pub finally_stmt: Option<Box<PhpStatement>>,
537}
538
539/// PHP `catch` clause.
540#[derive(Debug, Clone, PartialEq)]
541#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
542pub struct PhpCatch {
543    /// Exception types to catch.
544    pub types: Vec<String>,
545    /// Variable to hold the exception.
546    pub variable: PhpVariable,
547    /// Catch block body.
548    pub statement: Box<PhpStatement>,
549}
550
551/// PHP `declare` item.
552#[derive(Debug, Clone, PartialEq)]
553#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
554pub struct PhpDeclareItem {
555    /// Directive name.
556    pub name: String,
557    /// Directive value.
558    pub value: Box<PhpExpression>,
559}
560
561/// PHP function declaration.
562#[derive(Debug, Clone, PartialEq)]
563#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
564pub struct PhpFunction {
565    /// Function name.
566    pub name: String,
567    /// Function parameters.
568    pub parameters: Vec<PhpParameter>,
569    /// Optional return type.
570    pub return_type: Option<PhpType>,
571    /// Function body.
572    pub body: Box<PhpStatement>,
573    /// Whether the function returns by reference.
574    pub by_ref: bool,
575}
576
577/// PHP function parameter.
578#[derive(Debug, Clone, PartialEq)]
579#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
580pub struct PhpParameter {
581    /// Parameter name.
582    pub name: String,
583    /// Optional type hint.
584    pub param_type: Option<PhpType>,
585    /// Optional default value.
586    pub default: Option<Box<PhpExpression>>,
587    /// Whether the parameter is passed by reference.
588    pub by_ref: bool,
589    /// Whether the parameter is variadic.
590    pub variadic: bool,
591}
592
593/// PHP type specification.
594#[derive(Debug, Clone, PartialEq)]
595#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
596pub enum PhpType {
597    /// A simple named type.
598    Named(String),
599    /// A nullable type (e.g., `?int`).
600    Nullable(Box<PhpType>),
601    /// A union type (e.g., `int|string`).
602    Union(Vec<PhpType>),
603}
604
605/// PHP class declaration.
606#[derive(Debug, Clone, PartialEq)]
607#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
608pub struct PhpClass {
609    /// Class name.
610    pub name: String,
611    /// Optional parent class.
612    pub extends: Option<String>,
613    /// Implemented interfaces.
614    pub implements: Vec<String>,
615    /// Class members (properties, methods, constants, etc.).
616    pub members: Vec<PhpClassMember>,
617    /// Class modifiers (abstract, final, etc.).
618    pub modifiers: Vec<PhpModifier>,
619}
620
621/// PHP class members.
622#[derive(Debug, Clone, PartialEq)]
623#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
624pub enum PhpClassMember {
625    /// A class property.
626    Property(PhpProperty),
627    /// A class method.
628    Method(PhpMethod),
629    /// A class constant.
630    Constant(PhpConstant),
631    /// A trait use statement.
632    Use(PhpTraitUse),
633}
634
635/// PHP class property.
636#[derive(Debug, Clone, PartialEq)]
637#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
638pub struct PhpProperty {
639    /// Property name.
640    pub name: String,
641    /// Optional type hint.
642    pub property_type: Option<PhpType>,
643    /// Optional default value.
644    pub default: Option<Box<PhpExpression>>,
645    /// Access modifiers (public, private, etc.).
646    pub modifiers: Vec<PhpModifier>,
647}
648
649/// PHP class method.
650#[derive(Debug, Clone, PartialEq)]
651#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
652pub struct PhpMethod {
653    /// Method name.
654    pub name: String,
655    /// Method parameters.
656    pub parameters: Vec<PhpParameter>,
657    /// Optional return type.
658    pub return_type: Option<PhpType>,
659    /// Method body (None for abstract methods).
660    pub body: Option<Box<PhpStatement>>,
661    /// Access and behavior modifiers.
662    pub modifiers: Vec<PhpModifier>,
663    /// Whether the method returns by reference.
664    pub by_ref: bool,
665}
666
667/// PHP constant declaration.
668#[derive(Debug, Clone, PartialEq)]
669#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
670pub struct PhpConstant {
671    /// Constant name.
672    pub name: String,
673    /// Constant value.
674    pub value: Box<PhpExpression>,
675    /// Optional access modifiers.
676    pub modifiers: Vec<PhpModifier>,
677}
678
679/// PHP trait use statement.
680#[derive(Debug, Clone, PartialEq)]
681#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
682pub struct PhpTraitUse {
683    /// Traits being used.
684    pub traits: Vec<String>,
685    /// Adaptation rules for trait members (aliasing, precedence).
686    pub adaptations: Vec<PhpTraitAdaptation>,
687}
688
689/// PHP trait adaptation rule.
690#[derive(Debug, Clone, PartialEq)]
691#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
692pub enum PhpTraitAdaptation {
693    /// Precedence rule (`insteadof`).
694    Precedence {
695        /// Method name.
696        method: String,
697        /// Trait name.
698        trait_name: String,
699        /// Traits that this method replaces.
700        insteadof: Vec<String>,
701    },
702    /// Alias rule (`as`).
703    Alias {
704        /// Method name.
705        method: String,
706        /// Optional trait name.
707        trait_name: Option<String>,
708        /// New alias name.
709        alias: String,
710        /// Optional visibility modifier.
711        modifier: Option<PhpModifier>,
712    },
713}
714
715/// PHP access and behavior modifiers.
716#[derive(Debug, Clone, PartialEq)]
717#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
718pub enum PhpModifier {
719    /// Public visibility.
720    Public,
721    /// Protected visibility.
722    Protected,
723    /// Private visibility.
724    Private,
725    /// Static member.
726    Static,
727    /// Abstract member or class.
728    Abstract,
729    /// Final member or class.
730    Final,
731}
732
733/// PHP interface declaration.
734#[derive(Debug, Clone, PartialEq)]
735#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
736pub struct PhpInterface {
737    /// Interface name.
738    pub name: String,
739    /// Parent interfaces.
740    pub extends: Vec<String>,
741    /// Interface members (methods and constants).
742    pub members: Vec<PhpInterfaceMember>,
743}
744
745/// PHP interface members.
746#[derive(Debug, Clone, PartialEq)]
747#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
748pub enum PhpInterfaceMember {
749    /// An interface method.
750    Method(PhpMethod),
751    /// An interface constant.
752    Constant(PhpConstant),
753}
754
755/// PHP trait declaration.
756#[derive(Debug, Clone, PartialEq)]
757#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
758pub struct PhpTrait {
759    /// Trait name.
760    pub name: String,
761    /// Trait members.
762    pub members: Vec<PhpClassMember>,
763}
764
765/// PHP namespace declaration.
766#[derive(Debug, Clone, PartialEq)]
767#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
768pub struct PhpNamespace {
769    /// Optional namespace name (None for global namespace).
770    pub name: Option<String>,
771    /// Items within the namespace.
772    pub items: Vec<PhpItem>,
773}
774
775/// PHP `use` statement.
776#[derive(Debug, Clone, PartialEq)]
777#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
778pub struct PhpUse {
779    /// List of symbols being imported.
780    pub uses: Vec<PhpUseItem>,
781    /// Type of the `use` statement (normal, function, or constant).
782    pub use_type: PhpUseType,
783}
784
785/// PHP `use` item.
786#[derive(Debug, Clone, PartialEq)]
787#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
788pub struct PhpUseItem {
789    /// Fully qualified name of the symbol.
790    pub name: String,
791    /// Optional alias (`as`).
792    pub alias: Option<String>,
793}
794
795/// PHP `use` types.
796#[derive(Debug, Clone, PartialEq)]
797#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
798pub enum PhpUseType {
799    /// Normal import (class, interface, trait, or namespace).
800    Normal,
801    /// Function import (`use function`).
802    Function,
803    /// Constant import (`use const`).
804    Const,
805}