@@ -29,10 +29,10 @@ final class VariadicMethodsVisitor extends NodeVisitorAbstract
29
29
30
30
private ?string $ inMethod = null ;
31
31
32
- /** @var array<string, array<string, true >> */
32
+ /** @var array<string, array<string, bool >> */
33
33
public static array $ cache = [];
34
34
35
- /** @var array<string, array<string, true >> */
35
+ /** @var array<string, array<string, bool >> */
36
36
private array $ variadicMethods = [];
37
37
38
38
public function beforeTraverse (array $ nodes ): ?array
@@ -94,6 +94,10 @@ public function enterNode(Node $node): ?Node
94
94
public function leaveNode (Node $ node ): ?Node
95
95
{
96
96
if ($ node instanceof ClassMethod) {
97
+ $ lastClass = $ this ->classStack [count ($ this ->classStack ) - 1 ] ?? null ;
98
+ if ($ lastClass !== null ) {
99
+ $ this ->variadicMethods [$ lastClass ][$ this ->inMethod ] ??= false ;
100
+ }
97
101
$ this ->inMethod = null ;
98
102
}
99
103
@@ -111,12 +115,18 @@ public function leaveNode(Node $node): ?Node
111
115
public function afterTraverse (array $ nodes ): ?array
112
116
{
113
117
if ($ this ->topNode !== null && $ this ->variadicMethods !== []) {
118
+ $ filteredMethods = [];
114
119
foreach ($ this ->variadicMethods as $ class => $ methods ) {
115
120
foreach ($ methods as $ name => $ variadic ) {
116
121
self ::$ cache [$ class ][$ name ] = $ variadic ;
122
+ if (!$ variadic ) {
123
+ continue ;
124
+ }
125
+
126
+ $ filteredMethods [$ class ][$ name ] = true ;
117
127
}
118
128
}
119
- $ this ->topNode ->setAttribute (self ::ATTRIBUTE_NAME , $ this -> variadicMethods );
129
+ $ this ->topNode ->setAttribute (self ::ATTRIBUTE_NAME , $ filteredMethods );
120
130
}
121
131
122
132
return null ;
0 commit comments