Skip to main content

oak_php/ast/
mod.rs

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