10
10
use PHPStan \Type \Generic \GenericClassStringType ;
11
11
use PHPStan \Type \Generic \GenericObjectType ;
12
12
use PHPStan \Type \ObjectType ;
13
- use PHPStan \Type \ObjectWithoutClassType ;
14
13
use PHPStan \Type \Type ;
15
14
use PHPStan \Type \TypeWithClassName ;
16
15
@@ -49,7 +48,7 @@ public function getTypeFromMethodCall(
49
48
): Type
50
49
{
51
50
if (count ($ methodCall ->args ) === 0 ) {
52
- return $ this ->getDefaultReturnType ($ methodReflection );
51
+ return $ this ->getDefaultReturnType ($ scope , $ methodCall -> args , $ methodReflection );
53
52
}
54
53
$ argType = $ scope ->getType ($ methodCall ->args [0 ]->value );
55
54
if ($ argType instanceof ConstantStringType) {
@@ -58,12 +57,12 @@ public function getTypeFromMethodCall(
58
57
} elseif ($ argType instanceof GenericClassStringType) {
59
58
$ classType = $ argType ->getGenericType ();
60
59
if (!$ classType instanceof TypeWithClassName) {
61
- return $ this ->getDefaultReturnType ($ methodReflection );
60
+ return $ this ->getDefaultReturnType ($ scope , $ methodCall -> args , $ methodReflection );
62
61
}
63
62
64
63
$ objectName = $ classType ->getClassName ();
65
64
} else {
66
- return $ this ->getDefaultReturnType ($ methodReflection );
65
+ return $ this ->getDefaultReturnType ($ scope , $ methodCall -> args , $ methodReflection );
67
66
}
68
67
69
68
$ repositoryClass = $ this ->metadataResolver ->getRepositoryClass ($ objectName );
@@ -73,17 +72,19 @@ public function getTypeFromMethodCall(
73
72
]);
74
73
}
75
74
76
- private function getDefaultReturnType (MethodReflection $ methodReflection ): Type
75
+ /**
76
+ * @param \PHPStan\Analyser\Scope $scope
77
+ * @param \PhpParser\Node\Arg[] $args
78
+ * @param \PHPStan\Reflection\MethodReflection $methodReflection
79
+ * @return \PHPStan\Type\Type
80
+ */
81
+ private function getDefaultReturnType (Scope $ scope , array $ args , MethodReflection $ methodReflection ): Type
77
82
{
78
- $ type = ParametersAcceptorSelector::selectSingle (
83
+ return ParametersAcceptorSelector::selectFromArgs (
84
+ $ scope ,
85
+ $ args ,
79
86
$ methodReflection ->getVariants ()
80
87
)->getReturnType ();
81
-
82
- if ($ type instanceof GenericObjectType) {
83
- $ type = new GenericObjectType ($ type ->getClassName (), [new ObjectWithoutClassType ()]);
84
- }
85
-
86
- return $ type ;
87
88
}
88
89
89
90
}
0 commit comments