1010use PHPStan \Type \Generic \GenericClassStringType ;
1111use PHPStan \Type \Generic \GenericObjectType ;
1212use PHPStan \Type \ObjectType ;
13- use PHPStan \Type \ObjectWithoutClassType ;
1413use PHPStan \Type \Type ;
1514use PHPStan \Type \TypeWithClassName ;
1615
@@ -49,7 +48,7 @@ public function getTypeFromMethodCall(
4948 ): Type
5049 {
5150 if (count ($ methodCall ->args ) === 0 ) {
52- return $ this ->getDefaultReturnType ($ methodReflection );
51+ return $ this ->getDefaultReturnType ($ scope , $ methodCall -> args , $ methodReflection );
5352 }
5453 $ argType = $ scope ->getType ($ methodCall ->args [0 ]->value );
5554 if ($ argType instanceof ConstantStringType) {
@@ -58,12 +57,12 @@ public function getTypeFromMethodCall(
5857 } elseif ($ argType instanceof GenericClassStringType) {
5958 $ classType = $ argType ->getGenericType ();
6059 if (!$ classType instanceof TypeWithClassName) {
61- return $ this ->getDefaultReturnType ($ methodReflection );
60+ return $ this ->getDefaultReturnType ($ scope , $ methodCall -> args , $ methodReflection );
6261 }
6362
6463 $ objectName = $ classType ->getClassName ();
6564 } else {
66- return $ this ->getDefaultReturnType ($ methodReflection );
65+ return $ this ->getDefaultReturnType ($ scope , $ methodCall -> args , $ methodReflection );
6766 }
6867
6968 $ repositoryClass = $ this ->metadataResolver ->getRepositoryClass ($ objectName );
@@ -73,17 +72,19 @@ public function getTypeFromMethodCall(
7372 ]);
7473 }
7574
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
7782 {
78- $ type = ParametersAcceptorSelector::selectSingle (
83+ return ParametersAcceptorSelector::selectFromArgs (
84+ $ scope ,
85+ $ args ,
7986 $ methodReflection ->getVariants ()
8087 )->getReturnType ();
81- 82- if ($ type instanceof GenericObjectType) {
83- $ type = new GenericObjectType ($ type ->getClassName (), [new ObjectWithoutClassType ()]);
84- }
85- 86- return $ type ;
8788 }
8889
8990}
0 commit comments