5
5
use PhpParser \Node \Expr \MethodCall ;
6
6
use PHPStan \Analyser \Scope ;
7
7
use PHPStan \Reflection \MethodReflection ;
8
+ use PHPStan \Reflection \ParametersAcceptorSelector ;
8
9
use PHPStan \Type \Constant \ConstantBooleanType ;
9
10
use PHPStan \Type \DynamicMethodReturnTypeExtension ;
10
11
use PHPStan \Type \Type ;
@@ -25,22 +26,25 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
25
26
26
27
public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
27
28
{
29
+ $ defaultReturnType = ParametersAcceptorSelector::selectSingle (
30
+ $ methodReflection ->getVariants ()
31
+ )->getReturnType ();
28
32
if (count ($ methodCall ->args ) < 2 ) {
29
- return $ methodReflection -> getReturnType () ;
33
+ return $ defaultReturnType ;
30
34
}
31
35
32
36
$ paramNeedExpr = $ methodCall ->args [1 ]->value ;
33
37
$ paramNeedType = $ scope ->getType ($ paramNeedExpr );
34
38
35
39
if ($ paramNeedType instanceof ConstantBooleanType) {
36
40
if ($ paramNeedType ->getValue ()) {
37
- return TypeCombinator::removeNull ($ methodReflection -> getReturnType () );
41
+ return TypeCombinator::removeNull ($ defaultReturnType );
38
42
}
39
43
40
- return TypeCombinator::addNull ($ methodReflection -> getReturnType () );
44
+ return TypeCombinator::addNull ($ defaultReturnType );
41
45
}
42
46
43
- return $ methodReflection -> getReturnType () ;
47
+ return $ defaultReturnType ;
44
48
}
45
49
46
50
}
0 commit comments