Skip to content

Commit 2004f84

Browse files
Fix Query::execute() return type
1 parent 2d3c230 commit 2004f84

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/Type/Doctrine/HydrationModeReturnTypeResolver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Type\Accessory\AccessoryArrayListType;
88
use PHPStan\Type\ArrayType;
99
use PHPStan\Type\BenevolentUnionType;
10+
use PHPStan\Type\Constant\ConstantIntegerType;
1011
use PHPStan\Type\IntegerRangeType;
1112
use PHPStan\Type\IntegerType;
1213
use PHPStan\Type\IterableType;
@@ -21,7 +22,7 @@ class HydrationModeReturnTypeResolver
2122

2223
public function getMethodReturnTypeForHydrationMode(
2324
string $methodName,
24-
int $hydrationMode,
25+
Type $hydrationMode,
2526
Type $queryKeyType,
2627
Type $queryResultType,
2728
?ObjectManager $objectManager
@@ -41,7 +42,11 @@ public function getMethodReturnTypeForHydrationMode(
4142
return null;
4243
}
4344

44-
switch ($hydrationMode) {
45+
if (!$hydrationMode instanceof ConstantIntegerType) {
46+
return null;
47+
}
48+
49+
switch ($hydrationMode->getValue()) {
4550
case AbstractQuery::HYDRATE_OBJECT:
4651
break;
4752
case AbstractQuery::HYDRATE_SIMPLEOBJECT:

src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Reflection\MethodReflection;
99
use PHPStan\Reflection\ParametersAcceptorSelector;
1010
use PHPStan\ShouldNotHappenException;
11-
use PHPStan\Type\Constant\ConstantIntegerType;
1211
use PHPStan\Type\Doctrine\HydrationModeReturnTypeResolver;
1312
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
1413
use PHPStan\Type\DynamicMethodReturnTypeExtension;
@@ -80,13 +79,9 @@ public function getTypeFromMethodCall(
8079

8180
$queryType = $scope->getType($methodCall->var);
8281

83-
if (!$hydrationMode instanceof ConstantIntegerType) {
84-
return null;
85-
}
86-
8782
return $this->hydrationModeReturnTypeResolver->getMethodReturnTypeForHydrationMode(
8883
$methodReflection->getName(),
89-
$hydrationMode->getValue(),
84+
$hydrationMode,
9085
$queryType->getTemplateType(AbstractQuery::class, 'TKey'),
9186
$queryType->getTemplateType(AbstractQuery::class, 'TResult'),
9287
$this->objectMetadataResolver->getObjectManager()

tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function test(Type $expectedType, string $dql, string $methodName, ?int $
8686

8787
$type = $resolver->getMethodReturnTypeForHydrationMode(
8888
$methodName,
89-
$this->getRealHydrationMode($methodName, $hydrationMode),
89+
new ConstantIntegerType($this->getRealHydrationMode($methodName, $hydrationMode)),
9090
$typeBuilder->getIndexType(),
9191
$typeBuilder->getResultType(),
9292
$entityManager

0 commit comments

Comments
 (0)