@@ -152,7 +152,7 @@ private function isVariadic(): bool
152
152
$ cachedResult = $ this ->cache ->load ($ key , $ variableCacheKey );
153
153
if ($ cachedResult === null ) {
154
154
$ nodes = $ this ->parser ->parseFile ($ fileName );
155
- $ result = !$ this ->callsFuncGetArgs ($ nodes )->no ();
155
+ $ result = !$ this ->containsVariadicFunction ($ nodes )->no ();
156
156
$ this ->cache ->save ($ key , $ variableCacheKey , $ result );
157
157
return $ result ;
158
158
}
@@ -167,7 +167,7 @@ private function isVariadic(): bool
167
167
/**
168
168
* @param Node[]|scalar[]|Node $node
169
169
*/
170
- private function callsFuncGetArgs (array |Node $ node ): TrinaryLogic
170
+ private function containsVariadicFunction (array |Node $ node ): TrinaryLogic
171
171
{
172
172
$ result = TrinaryLogic::createMaybe ();
173
173
@@ -176,8 +176,7 @@ private function callsFuncGetArgs(array|Node $node): TrinaryLogic
176
176
$ functionName = (string ) $ node ->namespacedName ;
177
177
178
178
if ($ functionName === $ this ->reflection ->getName ()) {
179
- // native variadic with ...$param is checked via ReflectionFunction->isVariadic()
180
- return TrinaryLogic::createFromBoolean ($ this ->functionCallStatementFinder ->findFunctionCallInStatements (ParametersAcceptor::VARIADIC_FUNCTIONS , $ node ->getStmts ()) !== null );
179
+ return TrinaryLogic::createFromBoolean ($ this ->isFunctionNodeVariadic ($ node ));
181
180
}
182
181
}
183
182
@@ -187,15 +186,15 @@ private function callsFuncGetArgs(array|Node $node): TrinaryLogic
187
186
continue ;
188
187
}
189
188
190
- $ result = $ result ->and ($ this ->callsFuncGetArgs ($ innerNode ));
189
+ $ result = $ result ->and ($ this ->containsVariadicFunction ($ innerNode ));
191
190
}
192
191
} elseif (is_array ($ node )) {
193
192
foreach ($ node as $ subNode ) {
194
193
if (!$ subNode instanceof Node) {
195
194
continue ;
196
195
}
197
196
198
- $ result = $ result ->and ($ this ->callsFuncGetArgs ($ subNode ));
197
+ $ result = $ result ->and ($ this ->containsVariadicFunction ($ subNode ));
199
198
}
200
199
}
201
200
@@ -301,4 +300,19 @@ public function acceptsNamedArguments(): bool
301
300
return $ this ->acceptsNamedArguments ;
302
301
}
303
302
303
+ private function isFunctionNodeVariadic (Function_ $ node ): bool
304
+ {
305
+ foreach ($ node ->params as $ parameter ) {
306
+ if ($ parameter ->variadic ) {
307
+ return true ;
308
+ }
309
+ }
310
+
311
+ if ($ this ->functionCallStatementFinder ->findFunctionCallInStatements (ParametersAcceptor::VARIADIC_FUNCTIONS , $ node ->getStmts ()) !== null ) {
312
+ return true ;
313
+ }
314
+
315
+ return false ;
316
+ }
317
+
304
318
}
0 commit comments