1010use PHPStan \Type \Generic \GenericClassStringType ;
1111use PHPStan \Type \Generic \GenericObjectType ;
1212use PHPStan \Type \ObjectType ;
13+ use PHPStan \Type \ObjectWithoutClassType ;
1314use PHPStan \Type \Type ;
1415use PHPStan \Type \TypeWithClassName ;
1516
@@ -48,7 +49,10 @@ public function getTypeFromMethodCall(
4849 ): Type
4950 {
5051 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+ );
5256 }
5357 $ argType = $ scope ->getType ($ methodCall ->args [0 ]->value );
5458 if ($ argType instanceof ConstantStringType) {
@@ -57,7 +61,10 @@ public function getTypeFromMethodCall(
5761 } elseif ($ argType instanceof GenericClassStringType) {
5862 $ classType = $ argType ->getGenericType ();
5963 if (!$ classType instanceof TypeWithClassName) {
60- return $ this ->getDefaultReturnType ($ scope , $ methodCall ->args , $ methodReflection );
64+ return new GenericObjectType (
65+ $ this ->metadataResolver ->getResolvedRepositoryClass (),
66+ [$ classType ]
67+ );
6168 }
6269
6370 $ objectName = $ classType ->getClassName ();
@@ -84,11 +91,19 @@ public function getTypeFromMethodCall(
8491 */
8592 private function getDefaultReturnType (Scope $ scope , array $ args , MethodReflection $ methodReflection ): Type
8693 {
87- return ParametersAcceptorSelector::selectFromArgs (
94+ $ defaultType = ParametersAcceptorSelector::selectFromArgs (
8895 $ scope ,
8996 $ args ,
9097 $ methodReflection ->getVariants ()
9198 )->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 ;
92107 }
93108
94109}
0 commit comments