Skip to content

Commit a73955f

Browse files
committed
SubNodeNames are known at static analysis time
1 parent 8eea230 commit a73955f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+660
-125
lines changed

lib/PhpParser/Internal/PrintableNewAnonClassNode.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class PrintableNewAnonClassNode extends Expr {
2929
/** @var Node\Stmt[] Statements */
3030
public array $stmts;
3131

32+
private const SUBNODE_NAMES = ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts'];
33+
3234
/**
3335
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups
3436
* @param (Node\Arg|Node\VariadicPlaceholder)[] $args Arguments
@@ -65,7 +67,10 @@ public function getType(): string {
6567
return 'Expr_PrintableNewAnonClass';
6668
}
6769

70+
/**
71+
* @return self::SUBNODE_NAMES
72+
*/
6873
public function getSubNodeNames(): array {
69-
return ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts'];
74+
return self::SUBNODE_NAMES;
7075
}
7176
}

lib/PhpParser/Node/Arg.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Arg extends NodeAbstract {
1414
/** @var bool Whether to unpack the argument */
1515
public bool $unpack;
1616

17+
private const SUBNODE_NAMES = ['name', 'value', 'byRef', 'unpack'];
18+
1719
/**
1820
* Constructs a function call argument node.
1921
*
@@ -34,8 +36,11 @@ public function __construct(
3436
$this->unpack = $unpack;
3537
}
3638

39+
/**
40+
* @return self::SUBNODE_NAMES
41+
*/
3742
public function getSubNodeNames(): array {
38-
return ['name', 'value', 'byRef', 'unpack'];
43+
return self::SUBNODE_NAMES;
3944
}
4045

4146
public function getType(): string {

lib/PhpParser/Node/ArrayItem.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class ArrayItem extends NodeAbstract {
1414
/** @var bool Whether to unpack the argument */
1515
public bool $unpack;
1616

17+
private const SUBNODE_NAMES = ['key', 'value', 'byRef', 'unpack'];
18+
1719
/**
1820
* Constructs an array item node.
1921
*
@@ -30,8 +32,11 @@ public function __construct(Expr $value, ?Expr $key = null, bool $byRef = false,
3032
$this->unpack = $unpack;
3133
}
3234

35+
/**
36+
* @return self::SUBNODE_NAMES
37+
*/
3338
public function getSubNodeNames(): array {
34-
return ['key', 'value', 'byRef', 'unpack'];
39+
return self::SUBNODE_NAMES;
3540
}
3641

3742
public function getType(): string {

lib/PhpParser/Node/Attribute.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Attribute extends NodeAbstract {
1212
/** @var list<Arg> Attribute arguments */
1313
public array $args;
1414

15+
private const SUBNODE_NAMES = ['name', 'args'];
16+
1517
/**
1618
* @param Node\Name $name Attribute name
1719
* @param list<Arg> $args Attribute arguments
@@ -23,8 +25,11 @@ public function __construct(Name $name, array $args = [], array $attributes = []
2325
$this->args = $args;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['name', 'args'];
32+
return self::SUBNODE_NAMES;
2833
}
2934

3035
public function getType(): string {

lib/PhpParser/Node/AttributeGroup.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class AttributeGroup extends NodeAbstract {
88
/** @var Attribute[] Attributes */
99
public array $attrs;
1010

11+
private const SUBNODE_NAMES = ['attrs'];
12+
1113
/**
1214
* @param Attribute[] $attrs PHP attributes
1315
* @param array<string, mixed> $attributes Additional node attributes
@@ -17,8 +19,11 @@ public function __construct(array $attrs, array $attributes = []) {
1719
$this->attrs = $attrs;
1820
}
1921

22+
/**
23+
* @return self::SUBNODE_NAMES
24+
*/
2025
public function getSubNodeNames(): array {
21-
return ['attrs'];
26+
return self::SUBNODE_NAMES;
2227
}
2328

2429
public function getType(): string {

lib/PhpParser/Node/ClosureUse.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class ClosureUse extends NodeAbstract {
1010
/** @var bool Whether to use by reference */
1111
public bool $byRef;
1212

13+
private const SUBNODE_NAMES = ['var', 'byRef'];
14+
1315
/**
1416
* Constructs a closure use node.
1517
*
@@ -23,8 +25,11 @@ public function __construct(Expr\Variable $var, bool $byRef = false, array $attr
2325
$this->byRef = $byRef;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['var', 'byRef'];
32+
return self::SUBNODE_NAMES;
2833
}
2934

3035
public function getType(): string {

lib/PhpParser/Node/Const_.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Const_ extends NodeAbstract {
1313
/** @var Name|null Namespaced name (if using NameResolver) */
1414
public ?Name $namespacedName;
1515

16+
private const SUBNODE_NAMES = ['name', 'value'];
17+
1618
/**
1719
* Constructs a const node for use in class const and const statements.
1820
*
@@ -26,8 +28,11 @@ public function __construct($name, Expr $value, array $attributes = []) {
2628
$this->value = $value;
2729
}
2830

31+
/**
32+
* @return self::SUBNODE_NAMES
33+
*/
2934
public function getSubNodeNames(): array {
30-
return ['name', 'value'];
35+
return self::SUBNODE_NAMES;
3136
}
3237

3338
public function getType(): string {

lib/PhpParser/Node/DeclareItem.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class DeclareItem extends NodeAbstract {
1111
/** @var Node\Expr Value */
1212
public Expr $value;
1313

14+
private const SUBNODE_NAMES = ['key', 'value'];
15+
1416
/**
1517
* Constructs a declare key=>value pair node.
1618
*
@@ -24,8 +26,11 @@ public function __construct($key, Node\Expr $value, array $attributes = []) {
2426
$this->value = $value;
2527
}
2628

29+
/**
30+
* @return self::SUBNODE_NAMES
31+
*/
2732
public function getSubNodeNames(): array {
28-
return ['key', 'value'];
33+
return self::SUBNODE_NAMES;
2934
}
3035

3136
public function getType(): string {

lib/PhpParser/Node/Expr/ArrayDimFetch.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class ArrayDimFetch extends Expr {
1010
/** @var null|Expr Array index / dim */
1111
public ?Expr $dim;
1212

13+
private const SUBNODE_NAMES = ['var', 'dim'];
14+
1315
/**
1416
* Constructs an array index fetch node.
1517
*
@@ -23,8 +25,11 @@ public function __construct(Expr $var, ?Expr $dim = null, array $attributes = []
2325
$this->dim = $dim;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['var', 'dim'];
32+
return self::SUBNODE_NAMES;
2833
}
2934

3035
public function getType(): string {

lib/PhpParser/Node/Expr/Array_.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Array_ extends Expr {
1313
/** @var ArrayItem[] Items */
1414
public array $items;
1515

16+
private const SUBNODE_NAMES = ['items'];
17+
1618
/**
1719
* Constructs an array node.
1820
*
@@ -24,8 +26,11 @@ public function __construct(array $items = [], array $attributes = []) {
2426
$this->items = $items;
2527
}
2628

29+
/**
30+
* @return self::SUBNODE_NAMES
31+
*/
2732
public function getSubNodeNames(): array {
28-
return ['items'];
33+
return self::SUBNODE_NAMES;
2934
}
3035

3136
public function getType(): string {

lib/PhpParser/Node/Expr/ArrowFunction.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class ArrowFunction extends Expr implements FunctionLike {
2424
/** @var Node\AttributeGroup[] */
2525
public array $attrGroups;
2626

27+
private const SUBNODE_NAMES = ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr'];
28+
2729
/**
2830
* @param array{
2931
* expr: Expr,
@@ -51,8 +53,11 @@ public function __construct(array $subNodes, array $attributes = []) {
5153
$this->attrGroups = $subNodes['attrGroups'] ?? [];
5254
}
5355

56+
/**
57+
* @return self::SUBNODE_NAMES
58+
*/
5459
public function getSubNodeNames(): array {
55-
return ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr'];
60+
return self::SUBNODE_NAMES;
5661
}
5762

5863
public function returnsByRef(): bool {

lib/PhpParser/Node/Expr/Assign.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Assign extends Expr {
1010
/** @var Expr Expression */
1111
public Expr $expr;
1212

13+
private const SUBNODE_NAMES = ['var', 'expr'];
14+
1315
/**
1416
* Constructs an assignment node.
1517
*
@@ -23,8 +25,11 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) {
2325
$this->expr = $expr;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['var', 'expr'];
32+
return self::SUBNODE_NAMES;
2833
}
2934

3035
public function getType(): string {

lib/PhpParser/Node/Expr/AssignOp.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ abstract class AssignOp extends Expr {
1010
/** @var Expr Expression */
1111
public Expr $expr;
1212

13+
private const SUBNODE_NAMES = ['var', 'expr'];
14+
1315
/**
1416
* Constructs a compound assignment operation node.
1517
*
@@ -23,7 +25,10 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) {
2325
$this->expr = $expr;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['var', 'expr'];
32+
return self::SUBNODE_NAMES;
2833
}
2934
}

lib/PhpParser/Node/Expr/AssignRef.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class AssignRef extends Expr {
1010
/** @var Expr Variable which is referenced */
1111
public Expr $expr;
1212

13+
private const SUBNODE_NAMES = ['var', 'expr'];
14+
1315
/**
1416
* Constructs an assignment node.
1517
*
@@ -23,8 +25,11 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) {
2325
$this->expr = $expr;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['var', 'expr'];
32+
return self::SUBNODE_NAMES;
2833
}
2934

3035
public function getType(): string {

lib/PhpParser/Node/Expr/BinaryOp.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ abstract class BinaryOp extends Expr {
1010
/** @var Expr The right hand side expression */
1111
public Expr $right;
1212

13+
private const SUBNODE_NAMES = ['left', 'right'];
14+
1315
/**
1416
* Constructs a binary operator node.
1517
*
@@ -23,8 +25,11 @@ public function __construct(Expr $left, Expr $right, array $attributes = []) {
2325
$this->right = $right;
2426
}
2527

28+
/**
29+
* @return self::SUBNODE_NAMES
30+
*/
2631
public function getSubNodeNames(): array {
27-
return ['left', 'right'];
32+
return self::SUBNODE_NAMES;
2833
}
2934

3035
/**

lib/PhpParser/Node/Expr/BitwiseNot.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class BitwiseNot extends Expr {
88
/** @var Expr Expression */
99
public Expr $expr;
1010

11+
private const SUBNODE_NAMES = ['expr'];
12+
1113
/**
1214
* Constructs a bitwise not node.
1315
*
@@ -19,8 +21,11 @@ public function __construct(Expr $expr, array $attributes = []) {
1921
$this->expr = $expr;
2022
}
2123

24+
/**
25+
* @return self::SUBNODE_NAMES
26+
*/
2227
public function getSubNodeNames(): array {
23-
return ['expr'];
28+
return self::SUBNODE_NAMES;
2429
}
2530

2631
public function getType(): string {

lib/PhpParser/Node/Expr/BooleanNot.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class BooleanNot extends Expr {
88
/** @var Expr Expression */
99
public Expr $expr;
1010

11+
private const SUBNODE_NAMES = ['expr'];
12+
1113
/**
1214
* Constructs a boolean not node.
1315
*
@@ -19,8 +21,11 @@ public function __construct(Expr $expr, array $attributes = []) {
1921
$this->expr = $expr;
2022
}
2123

24+
/**
25+
* @return self::SUBNODE_NAMES
26+
*/
2227
public function getSubNodeNames(): array {
23-
return ['expr'];
28+
return self::SUBNODE_NAMES;
2429
}
2530

2631
public function getType(): string {

lib/PhpParser/Node/Expr/Cast.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ abstract class Cast extends Expr {
88
/** @var Expr Expression */
99
public Expr $expr;
1010

11+
private const SUBNODE_NAMES = ['expr'];
12+
1113
/**
1214
* Constructs a cast node.
1315
*
@@ -19,7 +21,10 @@ public function __construct(Expr $expr, array $attributes = []) {
1921
$this->expr = $expr;
2022
}
2123

24+
/**
25+
* @return self::SUBNODE_NAMES
26+
*/
2227
public function getSubNodeNames(): array {
23-
return ['expr'];
28+
return self::SUBNODE_NAMES;
2429
}
2530
}

0 commit comments

Comments
 (0)