@@ -93,20 +93,23 @@ public function methodCallReturnType(
9393 }
9494
9595 if (count ($ resolvedTypes ) > 0 ) {
96- $ remainingType = $ typeWithMethod ;
97- foreach ($ handledClassNames as $ handledClassName ) {
98- $ remainingType = TypeCombinator::remove ($ remainingType , new ObjectType ($ handledClassName ));
99- }
100- if ($ remainingType ->hasMethod ($ methodName )->yes ()) {
101- $ remainingMethod = $ remainingType ->getMethod ($ methodName , $ scope );
102- $ remainingParametersAcceptor = ParametersAcceptorSelector::selectFromArgs (
103- $ scope ,
104- $ methodCall ->getArgs (),
105- $ remainingMethod ->getVariants (),
106- $ remainingMethod ->getNamedArgumentsVariants (),
107- );
108- $ resolvedTypes [] = $ remainingParametersAcceptor ->getReturnType ();
96+ if (count ($ allClassNames ) !== count ($ handledClassNames )) {
97+ $ remainingType = $ typeWithMethod ;
98+ foreach ($ handledClassNames as $ handledClassName ) {
99+ $ remainingType = TypeCombinator::remove ($ remainingType , new ObjectType ($ handledClassName ));
100+ }
101+ if ($ remainingType ->hasMethod ($ methodName )->yes ()) {
102+ $ remainingMethod = $ remainingType ->getMethod ($ methodName , $ scope );
103+ $ remainingParametersAcceptor = ParametersAcceptorSelector::selectFromArgs (
104+ $ scope ,
105+ $ methodCall ->getArgs (),
106+ $ remainingMethod ->getVariants (),
107+ $ remainingMethod ->getNamedArgumentsVariants (),
108+ );
109+ $ resolvedTypes [] = $ remainingParametersAcceptor ->getReturnType ();
110+ }
109111 }
112+
110113 return VoidToNullTypeTransformer::transform (TypeCombinator::union (...$ resolvedTypes ), $ methodCall );
111114 }
112115
0 commit comments