@@ -476,7 +476,15 @@ public function specifyTypesInCondition(
476
476
477
477
} elseif ($ expr instanceof FuncCall && $ expr ->name instanceof Name) {
478
478
if ($ this ->reflectionProvider ->hasFunction ($ expr ->name , $ scope )) {
479
+ // lazy create parametersAcceptor, as creation can be expensive
480
+ $ parametersAcceptor = null ;
481
+
479
482
$ 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
+
480
488
foreach ($ this ->getFunctionTypeSpecifyingExtensions () as $ extension ) {
481
489
if (!$ extension ->isFunctionSupported ($ functionReflection , $ expr , $ context )) {
482
490
continue ;
@@ -485,10 +493,10 @@ public function specifyTypesInCondition(
485
493
return $ extension ->specifyTypes ($ functionReflection , $ expr , $ scope , $ context );
486
494
}
487
495
488
- // lazy create parametersAcceptor, as creation can be expensive
489
- $ parametersAcceptor = null ;
490
496
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
+ }
492
500
493
501
$ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
494
502
if ($ specifiedTypes !== null ) {
@@ -518,6 +526,14 @@ public function specifyTypesInCondition(
518
526
$ methodCalledOnType = $ scope ->getType ($ expr ->var );
519
527
$ methodReflection = $ scope ->getMethodReflection ($ methodCalledOnType , $ expr ->name ->name );
520
528
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
+
521
537
$ referencedClasses = $ methodCalledOnType ->getObjectClassNames ();
522
538
if (
523
539
count ($ referencedClasses ) === 1
@@ -533,10 +549,10 @@ public function specifyTypesInCondition(
533
549
}
534
550
}
535
551
536
- // lazy create parametersAcceptor, as creation can be expensive
537
- $ parametersAcceptor = null ;
538
552
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
+ }
540
556
541
557
$ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
542
558
if ($ specifiedTypes !== null ) {
@@ -571,6 +587,14 @@ public function specifyTypesInCondition(
571
587
572
588
$ staticMethodReflection = $ scope ->getMethodReflection ($ calleeType , $ expr ->name ->name );
573
589
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
+
574
598
$ referencedClasses = $ calleeType ->getObjectClassNames ();
575
599
if (
576
600
count ($ referencedClasses ) === 1
@@ -586,10 +610,10 @@ public function specifyTypesInCondition(
586
610
}
587
611
}
588
612
589
- // lazy create parametersAcceptor, as creation can be expensive
590
- $ parametersAcceptor = null ;
591
613
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
+ }
593
617
594
618
$ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
595
619
if ($ specifiedTypes !== null ) {
0 commit comments