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 ;
13
14
use PHPStan \Type \Type ;
14
15
use PHPStan \Type \TypeWithClassName ;
15
16
@@ -48,7 +49,10 @@ public function getTypeFromMethodCall(
48
49
): Type
49
50
{
50
51
if (count ($ methodCall ->args ) === 0 ) {
51
- return $ this ->getDefaultReturnType ($ scope , $ methodCall ->args , $ methodReflection );
52
+ return new GenericObjectType (
53
+ $ this ->metadataResolver ->getResolvedRepositoryClass (),
54
+ [new ObjectWithoutClassType ()]
55
+ );
52
56
}
53
57
$ argType = $ scope ->getType ($ methodCall ->args [0 ]->value );
54
58
if ($ argType instanceof ConstantStringType) {
@@ -57,7 +61,10 @@ public function getTypeFromMethodCall(
57
61
} elseif ($ argType instanceof GenericClassStringType) {
58
62
$ classType = $ argType ->getGenericType ();
59
63
if (!$ classType instanceof TypeWithClassName) {
60
- return $ this ->getDefaultReturnType ($ scope , $ methodCall ->args , $ methodReflection );
64
+ return new GenericObjectType (
65
+ $ this ->metadataResolver ->getResolvedRepositoryClass (),
66
+ [$ classType ]
67
+ );
61
68
}
62
69
63
70
$ objectName = $ classType ->getClassName ();
@@ -84,11 +91,19 @@ public function getTypeFromMethodCall(
84
91
*/
85
92
private function getDefaultReturnType (Scope $ scope , array $ args , MethodReflection $ methodReflection ): Type
86
93
{
87
- return ParametersAcceptorSelector::selectFromArgs (
94
+ $ defaultType = ParametersAcceptorSelector::selectFromArgs (
88
95
$ scope ,
89
96
$ args ,
90
97
$ methodReflection ->getVariants ()
91
98
)->getReturnType ();
99
+ if ($ defaultType instanceof GenericObjectType && count ($ defaultType ->getTypes ()) > 0 ) {
100
+ return new GenericObjectType (
101
+ $ this ->metadataResolver ->getResolvedRepositoryClass (),
102
+ [$ defaultType ->getTypes ()[0 ]]
103
+ );
104
+ }
105
+
106
+ return $ defaultType ;
92
107
}
93
108
94
109
}
0 commit comments