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(Serialize, 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(Serialize, 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(Serialize, 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(Serialize, 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(Serialize, 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(Serialize, 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(Serialize, 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(Serialize, Deserialize))]
164pub struct PhpFunctionCall {
165    pub name: Box<PhpExpression>,
166    pub arguments: Vec<PhpExpression>,
167}
168
169/// PHP method call
170#[derive(Debug, Clone, PartialEq)]
171#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
172pub struct PhpMethodCall {
173    pub object: Box<PhpExpression>,
174    pub method: String,
175    pub arguments: Vec<PhpExpression>,
176}
177
178/// PHP property access
179#[derive(Debug, Clone, PartialEq)]
180#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
181pub struct PhpPropertyAccess {
182    pub object: Box<PhpExpression>,
183    pub property: String,
184}
185
186/// PHP array access
187#[derive(Debug, Clone, PartialEq)]
188#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
189pub struct PhpArrayAccess {
190    pub array: Box<PhpExpression>,
191    pub index: Box<PhpExpression>,
192}
193
194/// PHP assignment
195#[derive(Debug, Clone, PartialEq)]
196#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
197pub struct PhpAssignment {
198    pub left: Box<PhpExpression>,
199    pub operator: PhpAssignmentOp,
200    pub right: Box<PhpExpression>,
201}
202
203/// PHP assignment operators.
204#[derive(Debug, Clone, PartialEq)]
205#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
206pub enum PhpAssignmentOp {
207    /// Standard assignment (`=`).
208    Assign,
209    /// Addition assignment (`+=`).
210    PlusAssign,
211    /// Subtraction assignment (`-=`).
212    MinusAssign,
213    /// Multiplication assignment (`*=`).
214    MultiplyAssign,
215    /// Division assignment (`/=`).
216    DivideAssign,
217    /// Modulo assignment (`%=`).
218    ModuloAssign,
219    /// Power assignment (`**=`).
220    PowerAssign,
221    /// Concatenation assignment (`.=`).
222    ConcatAssign,
223    /// Bitwise AND assignment (`&=`).
224    BitwiseAndAssign,
225    /// Bitwise OR assignment (`|=`).
226    BitwiseOrAssign,
227    /// Bitwise XOR assignment (`^=`).
228    BitwiseXorAssign,
229    /// Left shift assignment (`<<=`).
230    LeftShiftAssign,
231    /// Right shift assignment (`>>=`).
232    RightShiftAssign,
233    /// Null coalesce assignment (`??=`).
234    NullCoalesceAssign,
235}
236
237/// PHP binary operations.
238#[derive(Debug, Clone, PartialEq)]
239#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
240pub struct PhpBinaryOp {
241    /// Left operand.
242    pub left: Box<PhpExpression>,
243    /// Binary operator.
244    pub operator: PhpBinaryOperator,
245    /// Right operand.
246    pub right: Box<PhpExpression>,
247}
248
249/// PHP binary operators.
250#[derive(Debug, Clone, PartialEq)]
251#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
252pub enum PhpBinaryOperator {
253    /// Addition (`+`).
254    Plus,
255    /// Subtraction (`-`).
256    Minus,
257    /// Multiplication (`*`).
258    Multiply,
259    /// Division (`/`).
260    Divide,
261    /// Modulo (`%`).
262    Modulo,
263    /// Power (`**`).
264    Power,
265    /// Concatenation (`.`).
266    Concat,
267    /// Equality (`==`).
268    Equal,
269    /// Inequality (`!=`).
270    NotEqual,
271    /// Identity (`===`).
272    Identical,
273    /// Non-identity (`!==`).
274    NotIdentical,
275    /// Less than (`<`).
276    Less,
277    /// Less than or equal to (`<=`).
278    LessEqual,
279    /// Greater than (`>`).
280    Greater,
281    /// Greater than or equal to (`>=`).
282    GreaterEqual,
283    /// Spaceship operator (`<=>`).
284    Spaceship,
285    /// Logical AND (`&&` or `and`).
286    LogicalAnd,
287    /// Logical OR (`||` or `or`).
288    LogicalOr,
289    /// Logical XOR (`xor`).
290    LogicalXor,
291    /// Bitwise AND (`&`).
292    BitwiseAnd,
293    /// Bitwise OR (`|`).
294    BitwiseOr,
295    /// Bitwise XOR (`^`).
296    BitwiseXor,
297    /// Left shift (`<<`).
298    LeftShift,
299    /// Right shift (`>>`).
300    RightShift,
301    /// Null coalesce (`??`).
302    NullCoalesce,
303}
304
305/// PHP unary operations.
306#[derive(Debug, Clone, PartialEq)]
307#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
308pub struct PhpUnaryOp {
309    /// Unary operator.
310    pub operator: PhpUnaryOperator,
311    /// Operand.
312    pub operand: Box<PhpExpression>,
313}
314
315/// PHP unary operators.
316#[derive(Debug, Clone, PartialEq)]
317#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
318pub enum PhpUnaryOperator {
319    /// Unary plus (`+`).
320    Plus,
321    /// Unary minus (`-`).
322    Minus,
323    /// Logical NOT (`!`).
324    LogicalNot,
325    /// Bitwise NOT (`~`).
326    BitwiseNot,
327    /// Pre-increment (`++$a`).
328    PreIncrement,
329    /// Post-increment (`$a++`).
330    PostIncrement,
331    /// Pre-decrement (`--$a`).
332    PreDecrement,
333    /// Post-decrement (`$a--`).
334    PostDecrement,
335    /// Error suppression (`@`).
336    ErrorSuppression,
337}
338
339/// PHP ternary operations.
340#[derive(Debug, Clone, PartialEq)]
341#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
342pub struct PhpTernaryOp {
343    /// Condition expression.
344    pub condition: Box<PhpExpression>,
345    /// Expression for true branch (optional for shorthand `?:`).
346    pub true_expr: Option<Box<PhpExpression>>,
347    /// Expression for false branch.
348    pub false_expr: Box<PhpExpression>,
349}
350
351/// PHP type casts.
352#[derive(Debug, Clone, PartialEq)]
353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
354pub struct PhpCast {
355    /// Target type for the cast.
356    pub cast_type: PhpCastType,
357    /// Expression to be cast.
358    pub expression: Box<PhpExpression>,
359}
360
361/// PHP cast types.
362#[derive(Debug, Clone, PartialEq)]
363#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
364pub enum PhpCastType {
365    /// Cast to integer (`(int)`).
366    Int,
367    /// Cast to float (`(float)`).
368    Float,
369    /// Cast to string (`(string)`).
370    String,
371    /// Cast to boolean (`(bool)`).
372    Bool,
373    /// Cast to array (`(array)`).
374    Array,
375    /// Cast to object (`(object)`).
376    Object,
377    /// Cast to unset (`(unset)`).
378    Unset,
379}
380
381/// PHP `new` expression.
382#[derive(Debug, Clone, PartialEq)]
383#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
384pub struct PhpNew {
385    /// Class name or expression.
386    pub class: Box<PhpExpression>,
387    /// Constructor arguments.
388    pub arguments: Vec<PhpExpression>,
389}
390
391/// PHP `instanceof` expression.
392#[derive(Debug, Clone, PartialEq)]
393#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
394pub struct PhpInstanceof {
395    /// Expression to check.
396    pub expression: Box<PhpExpression>,
397    /// Class name or expression.
398    pub class: Box<PhpExpression>,
399}
400
401/// PHP `include` expression.
402#[derive(Debug, Clone, PartialEq)]
403#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
404pub struct PhpInclude {
405    /// Whether it is `include_once`.
406    pub once: bool,
407    /// Path to the file.
408    pub path: Box<PhpExpression>,
409}
410
411/// PHP `require` expression.
412#[derive(Debug, Clone, PartialEq)]
413#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
414pub struct PhpRequire {
415    /// Whether it is `require_once`.
416    pub once: bool,
417    /// Path to the file.
418    pub path: Box<PhpExpression>,
419}
420
421/// PHP `yield` expression.
422#[derive(Debug, Clone, PartialEq)]
423#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
424pub struct PhpYield {
425    /// Optional key for yield (e.g., `yield $key => $value`).
426    pub key: Option<Box<PhpExpression>>,
427    /// Optional value for yield.
428    pub value: Option<Box<PhpExpression>>,
429    /// Whether it is a `yield from` expression.
430    pub from: bool,
431}
432
433/// PHP `if` statement.
434#[derive(Debug, Clone, PartialEq)]
435#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
436pub struct PhpIf {
437    /// Condition expression.
438    pub condition: Box<PhpExpression>,
439    /// The `then` block.
440    pub then_stmt: Box<PhpStatement>,
441    /// Any `elseif` blocks.
442    pub elseif_stmts: Vec<PhpElseif>,
443    /// Optional `else` block.
444    pub else_stmt: Option<Box<PhpStatement>>,
445}
446
447/// PHP `elseif` statement.
448#[derive(Debug, Clone, PartialEq)]
449#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
450pub struct PhpElseif {
451    /// Condition expression.
452    pub condition: Box<PhpExpression>,
453    /// The `elseif` block.
454    pub statement: Box<PhpStatement>,
455}
456
457/// PHP `while` loop.
458#[derive(Debug, Clone, PartialEq)]
459#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
460pub struct PhpWhile {
461    /// Loop condition.
462    pub condition: Box<PhpExpression>,
463    /// Loop body.
464    pub statement: Box<PhpStatement>,
465}
466
467/// PHP `for` loop.
468#[derive(Debug, Clone, PartialEq)]
469#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
470pub struct PhpFor {
471    /// Loop initialization expressions.
472    pub init: Vec<PhpExpression>,
473    /// Loop conditions.
474    pub condition: Vec<PhpExpression>,
475    /// Loop update expressions.
476    pub update: Vec<PhpExpression>,
477    /// Loop body.
478    pub statement: Box<PhpStatement>,
479}
480
481/// PHP `foreach` loop.
482#[derive(Debug, Clone, PartialEq)]
483#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
484pub struct PhpForeach {
485    /// Iterable expression.
486    pub iterable: Box<PhpExpression>,
487    /// Optional key variable.
488    pub key: Option<Box<PhpExpression>>,
489    /// Value variable.
490    pub value: Box<PhpExpression>,
491    /// Loop body.
492    pub statement: Box<PhpStatement>,
493}
494
495/// PHP `switch` statement.
496#[derive(Debug, Clone, PartialEq)]
497#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
498pub struct PhpSwitch {
499    /// Expression to switch on.
500    pub expression: Box<PhpExpression>,
501    /// Switch cases.
502    pub cases: Vec<PhpCase>,
503}
504
505/// PHP `case` statement.
506#[derive(Debug, Clone, PartialEq)]
507#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
508pub struct PhpCase {
509    /// Case value (None for the `default` case).
510    pub value: Option<Box<PhpExpression>>,
511    /// Statements within the case.
512    pub statements: Vec<PhpStatement>,
513}
514
515/// PHP `try-catch-finally` block.
516#[derive(Debug, Clone, PartialEq)]
517#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
518pub struct PhpTry {
519    /// The `try` block.
520    pub statement: Box<PhpStatement>,
521    /// Catch clauses.
522    pub catches: Vec<PhpCatch>,
523    /// Optional `finally` block.
524    pub finally_stmt: Option<Box<PhpStatement>>,
525}
526
527/// PHP `catch` clause.
528#[derive(Debug, Clone, PartialEq)]
529#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
530pub struct PhpCatch {
531    /// Exception types to catch.
532    pub types: Vec<String>,
533    /// Variable to hold the exception.
534    pub variable: PhpVariable,
535    /// Catch block body.
536    pub statement: Box<PhpStatement>,
537}
538
539/// PHP `declare` item.
540#[derive(Debug, Clone, PartialEq)]
541#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
542pub struct PhpDeclareItem {
543    /// Directive name.
544    pub name: String,
545    /// Directive value.
546    pub value: Box<PhpExpression>,
547}
548
549/// PHP function declaration.
550#[derive(Debug, Clone, PartialEq)]
551#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
552pub struct PhpFunction {
553    /// Function name.
554    pub name: String,
555    /// Function parameters.
556    pub parameters: Vec<PhpParameter>,
557    /// Optional return type.
558    pub return_type: Option<PhpType>,
559    /// Function body.
560    pub body: Box<PhpStatement>,
561    /// Whether the function returns by reference.
562    pub by_ref: bool,
563}
564
565/// PHP function parameter.
566#[derive(Debug, Clone, PartialEq)]
567#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
568pub struct PhpParameter {
569    /// Parameter name.
570    pub name: String,
571    /// Optional type hint.
572    pub param_type: Option<PhpType>,
573    /// Optional default value.
574    pub default: Option<Box<PhpExpression>>,
575    /// Whether the parameter is passed by reference.
576    pub by_ref: bool,
577    /// Whether the parameter is variadic.
578    pub variadic: bool,
579}
580
581/// PHP type specification.
582#[derive(Debug, Clone, PartialEq)]
583#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
584pub enum PhpType {
585    /// A simple named type.
586    Named(String),
587    /// A nullable type (e.g., `?int`).
588    Nullable(Box<PhpType>),
589    /// A union type (e.g., `int|string`).
590    Union(Vec<PhpType>),
591}
592
593/// PHP class declaration.
594#[derive(Debug, Clone, PartialEq)]
595#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
596pub struct PhpClass {
597    /// Class name.
598    pub name: String,
599    /// Optional parent class.
600    pub extends: Option<String>,
601    /// Implemented interfaces.
602    pub implements: Vec<String>,
603    /// Class members (properties, methods, constants, etc.).
604    pub members: Vec<PhpClassMember>,
605    /// Class modifiers (abstract, final, etc.).
606    pub modifiers: Vec<PhpModifier>,
607}
608
609/// PHP class members.
610#[derive(Debug, Clone, PartialEq)]
611#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
612pub enum PhpClassMember {
613    /// A class property.
614    Property(PhpProperty),
615    /// A class method.
616    Method(PhpMethod),
617    /// A class constant.
618    Constant(PhpConstant),
619    /// A trait use statement.
620    Use(PhpTraitUse),
621}
622
623/// PHP class property.
624#[derive(Debug, Clone, PartialEq)]
625#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
626pub struct PhpProperty {
627    /// Property name.
628    pub name: String,
629    /// Optional type hint.
630    pub property_type: Option<PhpType>,
631    /// Optional default value.
632    pub default: Option<Box<PhpExpression>>,
633    /// Access modifiers (public, private, etc.).
634    pub modifiers: Vec<PhpModifier>,
635}
636
637/// PHP class method.
638#[derive(Debug, Clone, PartialEq)]
639#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
640pub struct PhpMethod {
641    /// Method name.
642    pub name: String,
643    /// Method parameters.
644    pub parameters: Vec<PhpParameter>,
645    /// Optional return type.
646    pub return_type: Option<PhpType>,
647    /// Method body (None for abstract methods).
648    pub body: Option<Box<PhpStatement>>,
649    /// Access and behavior modifiers.
650    pub modifiers: Vec<PhpModifier>,
651    /// Whether the method returns by reference.
652    pub by_ref: bool,
653}
654
655/// PHP constant declaration.
656#[derive(Debug, Clone, PartialEq)]
657#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
658pub struct PhpConstant {
659    /// Constant name.
660    pub name: String,
661    /// Constant value.
662    pub value: Box<PhpExpression>,
663    /// Optional access modifiers.
664    pub modifiers: Vec<PhpModifier>,
665}
666
667/// PHP trait use statement.
668#[derive(Debug, Clone, PartialEq)]
669#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
670pub struct PhpTraitUse {
671    /// Traits being used.
672    pub traits: Vec<String>,
673    /// Adaptation rules for trait members (aliasing, precedence).
674    pub adaptations: Vec<PhpTraitAdaptation>,
675}
676
677/// PHP trait adaptation rule.
678#[derive(Debug, Clone, PartialEq)]
679#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
680pub enum PhpTraitAdaptation {
681    /// Precedence rule (`insteadof`).
682    Precedence {
683        /// Method name.
684        method: String,
685        /// Trait name.
686        trait_name: String,
687        /// Traits that this method replaces.
688        insteadof: Vec<String>,
689    },
690    /// Alias rule (`as`).
691    Alias {
692        /// Method name.
693        method: String,
694        /// Optional trait name.
695        trait_name: Option<String>,
696        /// New alias name.
697        alias: String,
698        /// Optional visibility modifier.
699        modifier: Option<PhpModifier>,
700    },
701}
702
703/// PHP access and behavior modifiers.
704#[derive(Debug, Clone, PartialEq)]
705#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
706pub enum PhpModifier {
707    /// Public visibility.
708    Public,
709    /// Protected visibility.
710    Protected,
711    /// Private visibility.
712    Private,
713    /// Static member.
714    Static,
715    /// Abstract member or class.
716    Abstract,
717    /// Final member or class.
718    Final,
719}
720
721/// PHP interface declaration.
722#[derive(Debug, Clone, PartialEq)]
723#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
724pub struct PhpInterface {
725    /// Interface name.
726    pub name: String,
727    /// Parent interfaces.
728    pub extends: Vec<String>,
729    /// Interface members (methods and constants).
730    pub members: Vec<PhpInterfaceMember>,
731}
732
733/// PHP interface members.
734#[derive(Debug, Clone, PartialEq)]
735#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
736pub enum PhpInterfaceMember {
737    /// An interface method.
738    Method(PhpMethod),
739    /// An interface constant.
740    Constant(PhpConstant),
741}
742
743/// PHP trait declaration.
744#[derive(Debug, Clone, PartialEq)]
745#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
746pub struct PhpTrait {
747    /// Trait name.
748    pub name: String,
749    /// Trait members.
750    pub members: Vec<PhpClassMember>,
751}
752
753/// PHP namespace declaration.
754#[derive(Debug, Clone, PartialEq)]
755#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
756pub struct PhpNamespace {
757    /// Optional namespace name (None for global namespace).
758    pub name: Option<String>,
759    /// Items within the namespace.
760    pub items: Vec<PhpItem>,
761}
762
763/// PHP `use` statement.
764#[derive(Debug, Clone, PartialEq)]
765#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
766pub struct PhpUse {
767    /// List of symbols being imported.
768    pub uses: Vec<PhpUseItem>,
769    /// Type of the `use` statement (normal, function, or constant).
770    pub use_type: PhpUseType,
771}
772
773/// PHP `use` item.
774#[derive(Debug, Clone, PartialEq)]
775#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
776pub struct PhpUseItem {
777    /// Fully qualified name of the symbol.
778    pub name: String,
779    /// Optional alias (`as`).
780    pub alias: Option<String>,
781}
782
783/// PHP `use` types.
784#[derive(Debug, Clone, PartialEq)]
785#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
786pub enum PhpUseType {
787    /// Normal import (class, interface, trait, or namespace).
788    Normal,
789    /// Function import (`use function`).
790    Function,
791    Const,
792}