@@ -482,24 +482,21 @@ public function specifyTypesInCondition(
482
482
$ parametersAcceptor = null ;
483
483
484
484
$ functionReflection = $ this ->reflectionProvider ->getFunction ($ expr ->name , $ scope );
485
+ $ normalizedExpr = $ expr ;
485
486
if (count ($ expr ->getArgs ()) > 0 ) {
486
487
$ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ functionReflection ->getVariants (), $ functionReflection ->getNamedArgumentsVariants ());
487
- $ expr = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
488
+ $ normalizedExpr = ArgumentsNormalizer::reorderFuncArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
488
489
}
489
490
490
491
foreach ($ this ->getFunctionTypeSpecifyingExtensions () as $ extension ) {
491
- if (!$ extension ->isFunctionSupported ($ functionReflection , $ expr , $ context )) {
492
+ if (!$ extension ->isFunctionSupported ($ functionReflection , $ normalizedExpr , $ context )) {
492
493
continue ;
493
494
}
494
495
495
- return $ extension ->specifyTypes ($ functionReflection , $ expr , $ scope , $ context );
496
+ return $ extension ->specifyTypes ($ functionReflection , $ normalizedExpr , $ scope , $ context );
496
497
}
497
498
498
499
if (count ($ expr ->getArgs ()) > 0 ) {
499
- if ($ parametersAcceptor === null ) {
500
- throw new ShouldNotHappenException ();
501
- }
502
-
503
500
$ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
504
501
if ($ specifiedTypes !== null ) {
505
502
return $ specifiedTypes ;
@@ -531,9 +528,10 @@ public function specifyTypesInCondition(
531
528
// lazy create parametersAcceptor, as creation can be expensive
532
529
$ parametersAcceptor = null ;
533
530
531
+ $ normalizedExpr = $ expr ;
534
532
if (count ($ expr ->getArgs ()) > 0 ) {
535
533
$ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ methodReflection ->getVariants (), $ methodReflection ->getNamedArgumentsVariants ());
536
- $ expr = ArgumentsNormalizer::reorderMethodArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
534
+ $ normalizedExpr = ArgumentsNormalizer::reorderMethodArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
537
535
}
538
536
539
537
$ referencedClasses = $ methodCalledOnType ->getObjectClassNames ();
@@ -543,19 +541,15 @@ public function specifyTypesInCondition(
543
541
) {
544
542
$ methodClassReflection = $ this ->reflectionProvider ->getClass ($ referencedClasses [0 ]);
545
543
foreach ($ this ->getMethodTypeSpecifyingExtensionsForClass ($ methodClassReflection ->getName ()) as $ extension ) {
546
- if (!$ extension ->isMethodSupported ($ methodReflection , $ expr , $ context )) {
544
+ if (!$ extension ->isMethodSupported ($ methodReflection , $ normalizedExpr , $ context )) {
547
545
continue ;
548
546
}
549
547
550
- return $ extension ->specifyTypes ($ methodReflection , $ expr , $ scope , $ context );
548
+ return $ extension ->specifyTypes ($ methodReflection , $ normalizedExpr , $ scope , $ context );
551
549
}
552
550
}
553
551
554
552
if (count ($ expr ->getArgs ()) > 0 ) {
555
- if ($ parametersAcceptor === null ) {
556
- throw new ShouldNotHappenException ();
557
- }
558
-
559
553
$ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
560
554
if ($ specifiedTypes !== null ) {
561
555
return $ specifiedTypes ;
@@ -592,9 +586,10 @@ public function specifyTypesInCondition(
592
586
// lazy create parametersAcceptor, as creation can be expensive
593
587
$ parametersAcceptor = null ;
594
588
589
+ $ normalizedExpr = $ expr ;
595
590
if (count ($ expr ->getArgs ()) > 0 ) {
596
591
$ parametersAcceptor = ParametersAcceptorSelector::selectFromArgs ($ scope , $ expr ->getArgs (), $ staticMethodReflection ->getVariants (), $ staticMethodReflection ->getNamedArgumentsVariants ());
597
- $ expr = ArgumentsNormalizer::reorderStaticCallArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
592
+ $ normalizedExpr = ArgumentsNormalizer::reorderStaticCallArguments ($ parametersAcceptor , $ expr ) ?? $ expr ;
598
593
}
599
594
600
595
$ referencedClasses = $ calleeType ->getObjectClassNames ();
@@ -604,19 +599,15 @@ public function specifyTypesInCondition(
604
599
) {
605
600
$ staticMethodClassReflection = $ this ->reflectionProvider ->getClass ($ referencedClasses [0 ]);
606
601
foreach ($ this ->getStaticMethodTypeSpecifyingExtensionsForClass ($ staticMethodClassReflection ->getName ()) as $ extension ) {
607
- if (!$ extension ->isStaticMethodSupported ($ staticMethodReflection , $ expr , $ context )) {
602
+ if (!$ extension ->isStaticMethodSupported ($ staticMethodReflection , $ normalizedExpr , $ context )) {
608
603
continue ;
609
604
}
610
605
611
- return $ extension ->specifyTypes ($ staticMethodReflection , $ expr , $ scope , $ context );
606
+ return $ extension ->specifyTypes ($ staticMethodReflection , $ normalizedExpr , $ scope , $ context );
612
607
}
613
608
}
614
609
615
610
if (count ($ expr ->getArgs ()) > 0 ) {
616
- if ($ parametersAcceptor === null ) {
617
- throw new ShouldNotHappenException ();
618
- }
619
-
620
611
$ specifiedTypes = $ this ->specifyTypesFromConditionalReturnType ($ context , $ expr , $ parametersAcceptor , $ scope );
621
612
if ($ specifiedTypes !== null ) {
622
613
return $ specifiedTypes ;
0 commit comments