Skip to content

Commit

Permalink
Fix Query::execute() return type
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Jul 2, 2024
1 parent 2d3c230 commit 2004f84
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/Type/Doctrine/HydrationModeReturnTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BenevolentUnionType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
Expand All @@ -21,7 +22,7 @@ class HydrationModeReturnTypeResolver

public function getMethodReturnTypeForHydrationMode(
string $methodName,
int $hydrationMode,
Type $hydrationMode,
Type $queryKeyType,
Type $queryResultType,
?ObjectManager $objectManager
Expand All @@ -41,7 +42,11 @@ public function getMethodReturnTypeForHydrationMode(
return null;
}

switch ($hydrationMode) {
if (!$hydrationMode instanceof ConstantIntegerType) {
return null;
}

switch ($hydrationMode->getValue()) {
case AbstractQuery::HYDRATE_OBJECT:
break;
case AbstractQuery::HYDRATE_SIMPLEOBJECT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Doctrine\HydrationModeReturnTypeResolver;
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
Expand Down Expand Up @@ -80,13 +79,9 @@ public function getTypeFromMethodCall(

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

if (!$hydrationMode instanceof ConstantIntegerType) {
return null;
}

return $this->hydrationModeReturnTypeResolver->getMethodReturnTypeForHydrationMode(
$methodReflection->getName(),
$hydrationMode->getValue(),
$hydrationMode,
$queryType->getTemplateType(AbstractQuery::class, 'TKey'),
$queryType->getTemplateType(AbstractQuery::class, 'TResult'),
$this->objectMetadataResolver->getObjectManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function test(Type $expectedType, string $dql, string $methodName, ?int $

$type = $resolver->getMethodReturnTypeForHydrationMode(
$methodName,
$this->getRealHydrationMode($methodName, $hydrationMode),
new ConstantIntegerType($this->getRealHydrationMode($methodName, $hydrationMode)),
$typeBuilder->getIndexType(),
$typeBuilder->getResultType(),
$entityManager
Expand Down

0 comments on commit 2004f84

Please sign in to comment.