@@ -21,6 +21,8 @@ final class VariadicMethodsVisitor extends NodeVisitorAbstract
21
21
22
22
private ?string $ inNamespace = null ;
23
23
24
+ private ?string $ inClassLike = null ;
25
+
24
26
/** @var array<string> */
25
27
private array $ classStack = [];
26
28
@@ -39,6 +41,7 @@ public function beforeTraverse(array $nodes): ?array
39
41
$ this ->variadicMethods = [];
40
42
$ this ->inNamespace = null ;
41
43
$ this ->classStack = [];
44
+ $ this ->inClassLike = null ;
42
45
$ this ->inMethod = null ;
43
46
$ this ->anonymousClassIndex = 0 ;
44
47
@@ -63,27 +66,25 @@ public function enterNode(Node $node): ?Node
63
66
}
64
67
65
68
$ 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 ] ??= [];
68
71
}
69
72
70
- if ($ this ->classStack !== [] && $ node instanceof ClassMethod) {
73
+ if ($ this ->inClassLike !== null && $ node instanceof ClassMethod) {
71
74
$ this ->inMethod = $ node ->name ->name ;
72
75
}
73
76
74
77
if (
75
- $ this ->classStack !== []
78
+ $ this ->inClassLike !== null
76
79
&& $ this ->inMethod !== null
77
80
&& $ node instanceof Node \Expr \FuncCall
78
81
&& $ node ->name instanceof Name
79
82
&& in_array ((string ) $ node ->name , ParametersAcceptor::VARIADIC_FUNCTIONS , true )
80
83
) {
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 ();
85
86
} else {
86
- $ this ->variadicMethods [$ inClassLike ][$ this ->inMethod ]->and (TrinaryLogic::createYes ());
87
+ $ this ->variadicMethods [$ this -> inClassLike ][$ this ->inMethod ]->and (TrinaryLogic::createYes ());
87
88
}
88
89
89
90
}
@@ -95,16 +96,20 @@ public function leaveNode(Node $node): ?Node
95
96
{
96
97
if (
97
98
$ node instanceof ClassMethod
98
- && $ this ->classStack !== []
99
+ && $ this ->inClassLike !== null
99
100
) {
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 ();
103
102
$ this ->inMethod = null ;
104
103
}
105
104
106
105
if ($ node instanceof Node \Stmt \ClassLike) {
107
106
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
+ }
108
113
}
109
114
110
115
if ($ node instanceof Node \Stmt \Namespace_ && $ node ->name !== null ) {
0 commit comments