@@ -29,10 +29,10 @@ final class VariadicMethodsVisitor extends NodeVisitorAbstract
2929
3030 private ?string $ inMethod = null ;
3131
32- /** @var array<string, array<string, true >> */
32+ /** @var array<string, array<string, bool >> */
3333 public static array $ cache = [];
3434
35- /** @var array<string, array<string, true >> */
35+ /** @var array<string, array<string, bool >> */
3636 private array $ variadicMethods = [];
3737
3838 public function beforeTraverse (array $ nodes ): ?array
@@ -94,6 +94,10 @@ public function enterNode(Node $node): ?Node
9494 public function leaveNode (Node $ node ): ?Node
9595 {
9696 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+ }
97101 $ this ->inMethod = null ;
98102 }
99103
@@ -111,12 +115,18 @@ public function leaveNode(Node $node): ?Node
111115 public function afterTraverse (array $ nodes ): ?array
112116 {
113117 if ($ this ->topNode !== null && $ this ->variadicMethods !== []) {
118+ $ filteredMethods = [];
114119 foreach ($ this ->variadicMethods as $ class => $ methods ) {
115120 foreach ($ methods as $ name => $ variadic ) {
116121 self ::$ cache [$ class ][$ name ] = $ variadic ;
122+ if (!$ variadic ) {
123+ continue ;
124+ }
125+
126+ $ filteredMethods [$ class ][$ name ] = true ;
117127 }
118128 }
119- $ this ->topNode ->setAttribute (self ::ATTRIBUTE_NAME , $ this -> variadicMethods );
129+ $ this ->topNode ->setAttribute (self ::ATTRIBUTE_NAME , $ filteredMethods );
120130 }
121131
122132 return null ;
0 commit comments