@@ -476,7 +476,15 @@ public function specifyTypesInCondition(
476476
477477 } elseif ($ expr instanceof FuncCall && $ expr ->name instanceof Name) {
478478 if ($ this ->reflectionProvider ->hasFunction ($ expr ->name , $ scope )) {
479+ // lazy create parametersAcceptor, as creation can be expensive
480+ $ parametersAcceptor = null ;
481+
479482 $ functionReflection = $ this ->reflectionProvider ->getFunction ($ expr ->name , $ scope );
483+ if (count ($ expr ->getArgs ()) > 0 ) {
484+ $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ functionReflection ->getVariants (), $ functionReflection ->getNamedArgumentsVariants ());
485+ $ expr = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
486+ }
487+
480488 foreach ($ this ->getFunctionTypeSpecifyingExtensions () as $ extension ) {
481489 if (!$ extension ->isFunctionSupported ($ functionReflection , $ expr , $ context )) {
482490 continue ;
@@ -485,10 +493,10 @@ public function specifyTypesInCondition(
485493 return $ extension ->specifyTypes ($ functionReflection , $ expr , $ scope , $ context );
486494 }
487495
488- // lazy create parametersAcceptor, as creation can be expensive
489- $ parametersAcceptor = null ;
490496 if (count ($ expr ->getArgs ()) > 0 ) {
491- $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ functionReflection ->getVariants (), $ functionReflection ->getNamedArgumentsVariants ());
497+ if ($ parametersAcceptor === null ) {
498+ throw new ShouldNotHappenException ();
499+ }
492500
493501 $ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
494502 if ($ specifiedTypes !== null ) {
@@ -518,6 +526,14 @@ public function specifyTypesInCondition(
518526 $ methodCalledOnType = $ scope ->getType ($ expr ->var );
519527 $ methodReflection = $ scope ->getMethodReflection ($ methodCalledOnType , $ expr ->name ->name );
520528 if ($ methodReflection !== null ) {
529+ // lazy create parametersAcceptor, as creation can be expensive
530+ $ parametersAcceptor = null ;
531+
532+ if (count ($ expr ->getArgs ()) > 0 ) {
533+ $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ methodReflection ->getVariants (), $ methodReflection ->getNamedArgumentsVariants ());
534+ $ expr = ArgumentsNormalizer::reorderMethodArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
535+ }
536+
521537 $ referencedClasses = $ methodCalledOnType ->getObjectClassNames ();
522538 if (
523539 count ($ referencedClasses ) === 1
@@ -533,10 +549,10 @@ public function specifyTypesInCondition(
533549 }
534550 }
535551
536- // lazy create parametersAcceptor, as creation can be expensive
537- $ parametersAcceptor = null ;
538552 if (count ($ expr ->getArgs ()) > 0 ) {
539- $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ methodReflection ->getVariants (), $ methodReflection ->getNamedArgumentsVariants ());
553+ if ($ parametersAcceptor === null ) {
554+ throw new ShouldNotHappenException ();
555+ }
540556
541557 $ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
542558 if ($ specifiedTypes !== null ) {
@@ -571,6 +587,14 @@ public function specifyTypesInCondition(
571587
572588 $ staticMethodReflection = $ scope ->getMethodReflection ($ calleeType , $ expr ->name ->name );
573589 if ($ staticMethodReflection !== null ) {
590+ // lazy create parametersAcceptor, as creation can be expensive
591+ $ parametersAcceptor = null ;
592+
593+ if (count ($ expr ->getArgs ()) > 0 ) {
594+ $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ staticMethodReflection ->getVariants (), $ staticMethodReflection ->getNamedArgumentsVariants ());
595+ $ expr = ArgumentsNormalizer::reorderStaticCallArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
596+ }
597+
574598 $ referencedClasses = $ calleeType ->getObjectClassNames ();
575599 if (
576600 count ($ referencedClasses ) === 1
@@ -586,10 +610,10 @@ public function specifyTypesInCondition(
586610 }
587611 }
588612
589- // lazy create parametersAcceptor, as creation can be expensive
590- $ parametersAcceptor = null ;
591613 if (count ($ expr ->getArgs ()) > 0 ) {
592- $ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ staticMethodReflection ->getVariants (), $ staticMethodReflection ->getNamedArgumentsVariants ());
614+ if ($ parametersAcceptor === null ) {
615+ throw new ShouldNotHappenException ();
616+ }
593617
594618 $ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
595619 if ($ specifiedTypes !== null ) {
0 commit comments