@@ -21,6 +21,8 @@ final class VariadicMethodsVisitor extends NodeVisitorAbstract
2121
2222 private ?string $ inNamespace = null ;
2323
24+ private ?string $ inClassLike = null ;
25+
2426 /** @var array<string> */
2527 private array $ classStack = [];
2628
@@ -39,6 +41,7 @@ public function beforeTraverse(array $nodes): ?array
3941 $ this ->variadicMethods = [];
4042 $ this ->inNamespace = null ;
4143 $ this ->classStack = [];
44+ $ this ->inClassLike = null ;
4245 $ this ->inMethod = null ;
4346 $ this ->anonymousClassIndex = 0 ;
4447
@@ -63,27 +66,25 @@ public function enterNode(Node $node): ?Node
6366 }
6467
6568 $ this ->classStack [] = $ className ;
66- $ inClassLike = $ this ->inNamespace !== null ? $ this ->inNamespace . '\\' . implode ('\\' , $ this ->classStack ) : implode ('\\' , $ this ->classStack );
67- $ this ->variadicMethods [$ inClassLike ] ??= [];
69+ $ this -> inClassLike = $ this ->inNamespace !== null ? $ this ->inNamespace . '\\' . implode ('\\' , $ this ->classStack ) : implode ('\\' , $ this ->classStack );
70+ $ this ->variadicMethods [$ this -> inClassLike ] ??= [];
6871 }
6972
70- if ($ this ->classStack !== [] && $ node instanceof ClassMethod) {
73+ if ($ this ->inClassLike !== null && $ node instanceof ClassMethod) {
7174 $ this ->inMethod = $ node ->name ->name ;
7275 }
7376
7477 if (
75- $ this ->classStack !== []
78+ $ this ->inClassLike !== null
7679 && $ this ->inMethod !== null
7780 && $ node instanceof Node \Expr \FuncCall
7881 && $ node ->name instanceof Name
7982 && in_array ((string ) $ node ->name , ParametersAcceptor::VARIADIC_FUNCTIONS , true )
8083 ) {
81- $ inClassLike = $ this ->inNamespace !== null ? $ this ->inNamespace . '\\' . implode ('\\' , $ this ->classStack ) : implode ('\\' , $ this ->classStack );
82-
83- if (!array_key_exists ($ this ->inMethod , $ this ->variadicMethods [$ inClassLike ])) {
84- $ this ->variadicMethods [$ inClassLike ][$ this ->inMethod ] = TrinaryLogic::createYes ();
84+ if (!array_key_exists ($ this ->inMethod , $ this ->variadicMethods [$ this ->inClassLike ])) {
85+ $ this ->variadicMethods [$ this ->inClassLike ][$ this ->inMethod ] = TrinaryLogic::createYes ();
8586 } else {
86- $ this ->variadicMethods [$ inClassLike ][$ this ->inMethod ]->and (TrinaryLogic::createYes ());
87+ $ this ->variadicMethods [$ this -> inClassLike ][$ this ->inMethod ]->and (TrinaryLogic::createYes ());
8788 }
8889
8990 }
@@ -95,16 +96,20 @@ public function leaveNode(Node $node): ?Node
9596 {
9697 if (
9798 $ node instanceof ClassMethod
98- && $ this ->classStack !== []
99+ && $ this ->inClassLike !== null
99100 ) {
100- $ inClassLike = $ this ->inNamespace !== null ? $ this ->inNamespace . '\\' . implode ('\\' , $ this ->classStack ) : implode ('\\' , $ this ->classStack );
101-
102- $ this ->variadicMethods [$ inClassLike ][$ node ->name ->name ] ??= TrinaryLogic::createNo ();
101+ $ this ->variadicMethods [$ this ->inClassLike ][$ node ->name ->name ] ??= TrinaryLogic::createNo ();
103102 $ this ->inMethod = null ;
104103 }
105104
106105 if ($ node instanceof Node \Stmt \ClassLike) {
107106 array_pop ($ this ->classStack );
107+
108+ if ($ this ->classStack !== []) {
109+ $ this ->inClassLike = $ this ->inNamespace !== null ? $ this ->inNamespace . '\\' . implode ('\\' , $ this ->classStack ) : implode ('\\' , $ this ->classStack );
110+ } else {
111+ $ this ->inClassLike = null ;
112+ }
108113 }
109114
110115 if ($ node instanceof Node \Stmt \Namespace_ && $ node ->name !== null ) {
0 commit comments