1515use PHPStan \Reflection \ReflectionProvider ;
1616use PHPStan \Reflection \ReflectionWithFilename ;
1717use PHPStan \Type \ClosureType ;
18+ use PHPStan \Type \Constant \ConstantStringType ;
1819
1920class DependencyResolver
2021{
@@ -172,7 +173,10 @@ public function resolveDependencies(\PhpParser\Node $node, Scope $scope): array
172173 foreach ($ exprType ->getIterableValueType ()->getReferencedClasses () as $ referencedClass ) {
173174 $ this ->addClassToDependencies ($ referencedClass , $ dependenciesReflections );
174175 }
175- } elseif ($ node instanceof Array_) {
176+ } elseif (
177+ $ node instanceof Array_
178+ && $ this ->considerArrayForCallableTest ($ scope , $ node )
179+ ) {
176180 $ arrayType = $ scope ->getType ($ node );
177181 if (!$ arrayType ->isCallable ()->no ()) {
178182 foreach ($ arrayType ->getCallableParametersAcceptors ($ scope ) as $ variant ) {
@@ -187,6 +191,20 @@ public function resolveDependencies(\PhpParser\Node $node, Scope $scope): array
187191 return $ dependenciesReflections ;
188192 }
189193
194+ private function considerArrayForCallableTest (Scope $ scope , Array_ $ arrayNode ): bool
195+ {
196+ if (!isset ($ arrayNode ->items [0 ])) {
197+ return false ;
198+ }
199+
200+ $ itemType = $ scope ->getType ($ arrayNode ->items [0 ]->value );
201+ if (!$ itemType instanceof ConstantStringType) {
202+ return true ;
203+ }
204+
205+ return $ itemType ->isClassString ();
206+ }
207+
190208 /**
191209 * @param string $className
192210 * @param ReflectionWithFilename[] $dependenciesReflections
0 commit comments