55use PhpParser \Node \Expr \MethodCall ;
66use PHPStan \Analyser \Scope ;
77use PHPStan \Reflection \MethodReflection ;
8+ use PHPStan \Reflection \ParametersAcceptorSelector ;
89use PHPStan \Type \Constant \ConstantBooleanType ;
910use PHPStan \Type \DynamicMethodReturnTypeExtension ;
1011use PHPStan \Type \Type ;
@@ -25,22 +26,25 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2526
2627 public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
2728 {
29+ $ defaultReturnType = ParametersAcceptorSelector::selectSingle (
30+ $ methodReflection ->getVariants ()
31+ )->getReturnType ();
2832 if (count ($ methodCall ->args ) < 2 ) {
29- return $ methodReflection -> getReturnType () ;
33+ return $ defaultReturnType ;
3034 }
3135
3236 $ paramNeedExpr = $ methodCall ->args [1 ]->value ;
3337 $ paramNeedType = $ scope ->getType ($ paramNeedExpr );
3438
3539 if ($ paramNeedType instanceof ConstantBooleanType) {
3640 if ($ paramNeedType ->getValue ()) {
37- return TypeCombinator::removeNull ($ methodReflection -> getReturnType () );
41+ return TypeCombinator::removeNull ($ defaultReturnType );
3842 }
3943
40- return TypeCombinator::addNull ($ methodReflection -> getReturnType () );
44+ return TypeCombinator::addNull ($ defaultReturnType );
4145 }
4246
43- return $ methodReflection -> getReturnType () ;
47+ return $ defaultReturnType ;
4448 }
4549
4650}
0 commit comments