oak-php 0.0.11

PHP server-side scripting language parser with support for web development and modern PHP features.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
#![doc = include_str!("readme.md")]

/// PHP AST root node.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpRoot {
    /// Top-level items in the PHP file.
    pub items: Vec<PhpItem>,
}

/// PHP top-level items.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpItem {
    /// Opening tag (`<?php`).
    OpenTag,
    /// Closing tag (`?>`).
    CloseTag,
    /// A PHP statement.
    Statement(PhpStatement),
    /// A function declaration.
    Function(PhpFunction),
    /// A class declaration.
    Class(PhpClass),
    /// An interface declaration.
    Interface(PhpInterface),
    /// A trait declaration.
    Trait(PhpTrait),
    /// A namespace declaration.
    Namespace(PhpNamespace),
    /// A use statement for importing symbols.
    Use(PhpUse),
}

/// PHP statements.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpStatement {
    /// An expression statement.
    Expression(PhpExpression),
    /// An `if` statement.
    If(PhpIf),
    /// A `while` loop.
    While(PhpWhile),
    /// A `for` loop.
    For(PhpFor),
    /// A `foreach` loop.
    Foreach(PhpForeach),
    /// A `switch` statement.
    Switch(PhpSwitch),
    /// A `try-catch-finally` block.
    Try(PhpTry),
    /// A `return` statement.
    Return(Option<PhpExpression>),
    /// A `break` statement.
    Break(Option<PhpExpression>),
    /// A `continue` statement.
    Continue(Option<PhpExpression>),
    /// An `echo` statement.
    Echo(Vec<PhpExpression>),
    /// A `print` statement.
    Print(PhpExpression),
    /// A `global` variable declaration.
    Global(Vec<String>),
    /// A `static` variable declaration.
    Static(Vec<PhpVariable>),
    /// An `unset` statement.
    Unset(Vec<PhpExpression>),
    /// A `declare` statement.
    Declare(Vec<PhpDeclareItem>),
    /// A block of statements enclosed in braces.
    Block(Vec<PhpStatement>),
}

/// PHP expressions.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpExpression {
    /// A literal value.
    Literal(PhpLiteral),
    /// A variable.
    Variable(PhpVariable),
    /// An array creation.
    Array(Vec<PhpArrayElement>),
    /// A function call.
    FunctionCall(PhpFunctionCall),
    /// A method call.
    MethodCall(PhpMethodCall),
    /// A property access.
    PropertyAccess(PhpPropertyAccess),
    /// An array element access.
    ArrayAccess(PhpArrayAccess),
    /// An assignment operation.
    Assignment(PhpAssignment),
    /// A binary operation.
    BinaryOp(PhpBinaryOp),
    /// A unary operation.
    UnaryOp(PhpUnaryOp),
    /// A ternary operation.
    TernaryOp(PhpTernaryOp),
    /// A type cast.
    Cast(PhpCast),
    /// An object instantiation.
    New(PhpNew),
    /// An object clone operation.
    Clone(Box<PhpExpression>),
    /// An `instanceof` check.
    Instanceof(PhpInstanceof),
    /// An `include` or `include_once` statement.
    Include(PhpInclude),
    /// A `require` or `require_once` statement.
    Require(PhpRequire),
    /// An `eval` call.
    Eval(Box<PhpExpression>),
    /// An `exit` or `die` call.
    Exit(Option<Box<PhpExpression>>),
    /// An `empty` check.
    Empty(Box<PhpExpression>),
    /// An `isset` check.
    Isset(Vec<PhpExpression>),
    /// A `list` or short array assignment.
    List(Vec<Option<PhpExpression>>),
    /// A `yield` expression for generators.
    Yield(PhpYield),
}

/// PHP literals.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpLiteral {
    /// A string literal.
    String(String),
    /// A numeric literal.
    Number(String),
    /// A boolean literal.
    Boolean(bool),
    /// The `null` literal.
    Null,
}

/// PHP variables.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpVariable {
    /// The name of the variable (including the `$` prefix).
    pub name: String,
}

/// PHP array elements.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpArrayElement {
    /// Optional key for the array element.
    pub key: Option<PhpExpression>,
    /// The value of the array element.
    pub value: PhpExpression,
}

/// PHP function call
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpFunctionCall {
    /// Function name or expression.
    pub name: Box<PhpExpression>,
    /// Function arguments.
    pub arguments: Vec<PhpExpression>,
}

/// PHP method call
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpMethodCall {
    /// Object expression.
    pub object: Box<PhpExpression>,
    /// Method name.
    pub method: String,
    /// Method arguments.
    pub arguments: Vec<PhpExpression>,
}

/// PHP property access
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpPropertyAccess {
    /// Object expression.
    pub object: Box<PhpExpression>,
    /// Property name.
    pub property: String,
}

/// PHP array access
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpArrayAccess {
    /// Array expression.
    pub array: Box<PhpExpression>,
    /// Index expression.
    pub index: Box<PhpExpression>,
}

/// PHP assignment
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpAssignment {
    /// Left-hand side expression.
    pub left: Box<PhpExpression>,
    /// Assignment operator.
    pub operator: PhpAssignmentOp,
    /// Right-hand side expression.
    pub right: Box<PhpExpression>,
}

/// PHP assignment operators.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpAssignmentOp {
    /// Standard assignment (`=`).
    Assign,
    /// Addition assignment (`+=`).
    PlusAssign,
    /// Subtraction assignment (`-=`).
    MinusAssign,
    /// Multiplication assignment (`*=`).
    MultiplyAssign,
    /// Division assignment (`/=`).
    DivideAssign,
    /// Modulo assignment (`%=`).
    ModuloAssign,
    /// Power assignment (`**=`).
    PowerAssign,
    /// Concatenation assignment (`.=`).
    ConcatAssign,
    /// Bitwise AND assignment (`&=`).
    BitwiseAndAssign,
    /// Bitwise OR assignment (`|=`).
    BitwiseOrAssign,
    /// Bitwise XOR assignment (`^=`).
    BitwiseXorAssign,
    /// Left shift assignment (`<<=`).
    LeftShiftAssign,
    /// Right shift assignment (`>>=`).
    RightShiftAssign,
    /// Null coalesce assignment (`??=`).
    NullCoalesceAssign,
}

/// PHP binary operations.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpBinaryOp {
    /// Left operand.
    pub left: Box<PhpExpression>,
    /// Binary operator.
    pub operator: PhpBinaryOperator,
    /// Right operand.
    pub right: Box<PhpExpression>,
}

/// PHP binary operators.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpBinaryOperator {
    /// Addition (`+`).
    Plus,
    /// Subtraction (`-`).
    Minus,
    /// Multiplication (`*`).
    Multiply,
    /// Division (`/`).
    Divide,
    /// Modulo (`%`).
    Modulo,
    /// Power (`**`).
    Power,
    /// Concatenation (`.`).
    Concat,
    /// Equality (`==`).
    Equal,
    /// Inequality (`!=`).
    NotEqual,
    /// Identity (`===`).
    Identical,
    /// Non-identity (`!==`).
    NotIdentical,
    /// Less than (`<`).
    Less,
    /// Less than or equal to (`<=`).
    LessEqual,
    /// Greater than (`>`).
    Greater,
    /// Greater than or equal to (`>=`).
    GreaterEqual,
    /// Spaceship operator (`<=>`).
    Spaceship,
    /// Logical AND (`&&` or `and`).
    LogicalAnd,
    /// Logical OR (`||` or `or`).
    LogicalOr,
    /// Logical XOR (`xor`).
    LogicalXor,
    /// Bitwise AND (`&`).
    BitwiseAnd,
    /// Bitwise OR (`|`).
    BitwiseOr,
    /// Bitwise XOR (`^`).
    BitwiseXor,
    /// Left shift (`<<`).
    LeftShift,
    /// Right shift (`>>`).
    RightShift,
    /// Null coalesce (`??`).
    NullCoalesce,
}

/// PHP unary operations.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpUnaryOp {
    /// Unary operator.
    pub operator: PhpUnaryOperator,
    /// Operand.
    pub operand: Box<PhpExpression>,
}

/// PHP unary operators.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpUnaryOperator {
    /// Unary plus (`+`).
    Plus,
    /// Unary minus (`-`).
    Minus,
    /// Logical NOT (`!`).
    LogicalNot,
    /// Bitwise NOT (`~`).
    BitwiseNot,
    /// Pre-increment (`++$a`).
    PreIncrement,
    /// Post-increment (`$a++`).
    PostIncrement,
    /// Pre-decrement (`--$a`).
    PreDecrement,
    /// Post-decrement (`$a--`).
    PostDecrement,
    /// Error suppression (`@`).
    ErrorSuppression,
}

/// PHP ternary operations.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpTernaryOp {
    /// Condition expression.
    pub condition: Box<PhpExpression>,
    /// Expression for true branch (optional for shorthand `?:`).
    pub true_expr: Option<Box<PhpExpression>>,
    /// Expression for false branch.
    pub false_expr: Box<PhpExpression>,
}

/// PHP type casts.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpCast {
    /// Target type for the cast.
    pub cast_type: PhpCastType,
    /// Expression to be cast.
    pub expression: Box<PhpExpression>,
}

/// PHP cast types.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpCastType {
    /// Cast to integer (`(int)`).
    Int,
    /// Cast to float (`(float)`).
    Float,
    /// Cast to string (`(string)`).
    String,
    /// Cast to boolean (`(bool)`).
    Bool,
    /// Cast to array (`(array)`).
    Array,
    /// Cast to object (`(object)`).
    Object,
    /// Cast to unset (`(unset)`).
    Unset,
}

/// PHP `new` expression.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpNew {
    /// Class name or expression.
    pub class: Box<PhpExpression>,
    /// Constructor arguments.
    pub arguments: Vec<PhpExpression>,
}

/// PHP `instanceof` expression.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpInstanceof {
    /// Expression to check.
    pub expression: Box<PhpExpression>,
    /// Class name or expression.
    pub class: Box<PhpExpression>,
}

/// PHP `include` expression.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpInclude {
    /// Whether it is `include_once`.
    pub once: bool,
    /// Path to the file.
    pub path: Box<PhpExpression>,
}

/// PHP `require` expression.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpRequire {
    /// Whether it is `require_once`.
    pub once: bool,
    /// Path to the file.
    pub path: Box<PhpExpression>,
}

/// PHP `yield` expression.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpYield {
    /// Optional key for yield (e.g., `yield $key => $value`).
    pub key: Option<Box<PhpExpression>>,
    /// Optional value for yield.
    pub value: Option<Box<PhpExpression>>,
    /// Whether it is a `yield from` expression.
    pub from: bool,
}

/// PHP `if` statement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpIf {
    /// Condition expression.
    pub condition: Box<PhpExpression>,
    /// The `then` block.
    pub then_stmt: Box<PhpStatement>,
    /// Any `elseif` blocks.
    pub elseif_stmts: Vec<PhpElseif>,
    /// Optional `else` block.
    pub else_stmt: Option<Box<PhpStatement>>,
}

/// PHP `elseif` statement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpElseif {
    /// Condition expression.
    pub condition: Box<PhpExpression>,
    /// The `elseif` block.
    pub statement: Box<PhpStatement>,
}

/// PHP `while` loop.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpWhile {
    /// Loop condition.
    pub condition: Box<PhpExpression>,
    /// Loop body.
    pub statement: Box<PhpStatement>,
}

/// PHP `for` loop.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpFor {
    /// Loop initialization expressions.
    pub init: Vec<PhpExpression>,
    /// Loop conditions.
    pub condition: Vec<PhpExpression>,
    /// Loop update expressions.
    pub update: Vec<PhpExpression>,
    /// Loop body.
    pub statement: Box<PhpStatement>,
}

/// PHP `foreach` loop.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpForeach {
    /// Iterable expression.
    pub iterable: Box<PhpExpression>,
    /// Optional key variable.
    pub key: Option<Box<PhpExpression>>,
    /// Value variable.
    pub value: Box<PhpExpression>,
    /// Loop body.
    pub statement: Box<PhpStatement>,
}

/// PHP `switch` statement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpSwitch {
    /// Expression to switch on.
    pub expression: Box<PhpExpression>,
    /// Switch cases.
    pub cases: Vec<PhpCase>,
}

/// PHP `case` statement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpCase {
    /// Case value (None for the `default` case).
    pub value: Option<Box<PhpExpression>>,
    /// Statements within the case.
    pub statements: Vec<PhpStatement>,
}

/// PHP `try-catch-finally` block.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpTry {
    /// The `try` block.
    pub statement: Box<PhpStatement>,
    /// Catch clauses.
    pub catches: Vec<PhpCatch>,
    /// Optional `finally` block.
    pub finally_stmt: Option<Box<PhpStatement>>,
}

/// PHP `catch` clause.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpCatch {
    /// Exception types to catch.
    pub types: Vec<String>,
    /// Variable to hold the exception.
    pub variable: PhpVariable,
    /// Catch block body.
    pub statement: Box<PhpStatement>,
}

/// PHP `declare` item.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpDeclareItem {
    /// Directive name.
    pub name: String,
    /// Directive value.
    pub value: Box<PhpExpression>,
}

/// PHP function declaration.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpFunction {
    /// Function name.
    pub name: String,
    /// Function parameters.
    pub parameters: Vec<PhpParameter>,
    /// Optional return type.
    pub return_type: Option<PhpType>,
    /// Function body.
    pub body: Box<PhpStatement>,
    /// Whether the function returns by reference.
    pub by_ref: bool,
}

/// PHP function parameter.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpParameter {
    /// Parameter name.
    pub name: String,
    /// Optional type hint.
    pub param_type: Option<PhpType>,
    /// Optional default value.
    pub default: Option<Box<PhpExpression>>,
    /// Whether the parameter is passed by reference.
    pub by_ref: bool,
    /// Whether the parameter is variadic.
    pub variadic: bool,
}

/// PHP type specification.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpType {
    /// A simple named type.
    Named(String),
    /// A nullable type (e.g., `?int`).
    Nullable(Box<PhpType>),
    /// A union type (e.g., `int|string`).
    Union(Vec<PhpType>),
}

/// PHP class declaration.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpClass {
    /// Class name.
    pub name: String,
    /// Optional parent class.
    pub extends: Option<String>,
    /// Implemented interfaces.
    pub implements: Vec<String>,
    /// Class members (properties, methods, constants, etc.).
    pub members: Vec<PhpClassMember>,
    /// Class modifiers (abstract, final, etc.).
    pub modifiers: Vec<PhpModifier>,
}

/// PHP class members.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpClassMember {
    /// A class property.
    Property(PhpProperty),
    /// A class method.
    Method(PhpMethod),
    /// A class constant.
    Constant(PhpConstant),
    /// A trait use statement.
    Use(PhpTraitUse),
}

/// PHP class property.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpProperty {
    /// Property name.
    pub name: String,
    /// Optional type hint.
    pub property_type: Option<PhpType>,
    /// Optional default value.
    pub default: Option<Box<PhpExpression>>,
    /// Access modifiers (public, private, etc.).
    pub modifiers: Vec<PhpModifier>,
}

/// PHP class method.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpMethod {
    /// Method name.
    pub name: String,
    /// Method parameters.
    pub parameters: Vec<PhpParameter>,
    /// Optional return type.
    pub return_type: Option<PhpType>,
    /// Method body (None for abstract methods).
    pub body: Option<Box<PhpStatement>>,
    /// Access and behavior modifiers.
    pub modifiers: Vec<PhpModifier>,
    /// Whether the method returns by reference.
    pub by_ref: bool,
}

/// PHP constant declaration.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpConstant {
    /// Constant name.
    pub name: String,
    /// Constant value.
    pub value: Box<PhpExpression>,
    /// Optional access modifiers.
    pub modifiers: Vec<PhpModifier>,
}

/// PHP trait use statement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpTraitUse {
    /// Traits being used.
    pub traits: Vec<String>,
    /// Adaptation rules for trait members (aliasing, precedence).
    pub adaptations: Vec<PhpTraitAdaptation>,
}

/// PHP trait adaptation rule.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpTraitAdaptation {
    /// Precedence rule (`insteadof`).
    Precedence {
        /// Method name.
        method: String,
        /// Trait name.
        trait_name: String,
        /// Traits that this method replaces.
        insteadof: Vec<String>,
    },
    /// Alias rule (`as`).
    Alias {
        /// Method name.
        method: String,
        /// Optional trait name.
        trait_name: Option<String>,
        /// New alias name.
        alias: String,
        /// Optional visibility modifier.
        modifier: Option<PhpModifier>,
    },
}

/// PHP access and behavior modifiers.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpModifier {
    /// Public visibility.
    Public,
    /// Protected visibility.
    Protected,
    /// Private visibility.
    Private,
    /// Static member.
    Static,
    /// Abstract member or class.
    Abstract,
    /// Final member or class.
    Final,
}

/// PHP interface declaration.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpInterface {
    /// Interface name.
    pub name: String,
    /// Parent interfaces.
    pub extends: Vec<String>,
    /// Interface members (methods and constants).
    pub members: Vec<PhpInterfaceMember>,
}

/// PHP interface members.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpInterfaceMember {
    /// An interface method.
    Method(PhpMethod),
    /// An interface constant.
    Constant(PhpConstant),
}

/// PHP trait declaration.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpTrait {
    /// Trait name.
    pub name: String,
    /// Trait members.
    pub members: Vec<PhpClassMember>,
}

/// PHP namespace declaration.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpNamespace {
    /// Optional namespace name (None for global namespace).
    pub name: Option<String>,
    /// Items within the namespace.
    pub items: Vec<PhpItem>,
}

/// PHP `use` statement.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpUse {
    /// List of symbols being imported.
    pub uses: Vec<PhpUseItem>,
    /// Type of the `use` statement (normal, function, or constant).
    pub use_type: PhpUseType,
}

/// PHP `use` item.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PhpUseItem {
    /// Fully qualified name of the symbol.
    pub name: String,
    /// Optional alias (`as`).
    pub alias: Option<String>,
}

/// PHP `use` types.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PhpUseType {
    /// Normal import (class, interface, trait, or namespace).
    Normal,
    /// Function import (`use function`).
    Function,
    /// Constant import (`use const`).
    Const,
}