Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5762a21

Browse files
Better solution for previous commit
1 parent 63165b7 commit 5762a21

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

‎src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Type\Generic\GenericClassStringType;
1111
use PHPStan\Type\Generic\GenericObjectType;
1212
use PHPStan\Type\ObjectType;
13-
use PHPStan\Type\ObjectWithoutClassType;
1413
use PHPStan\Type\Type;
1514
use 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /