diff --git a/src/Type/Doctrine/HydrationModeReturnTypeResolver.php b/src/Type/Doctrine/HydrationModeReturnTypeResolver.php index dabf4d9b..2f1c8e36 100644 --- a/src/Type/Doctrine/HydrationModeReturnTypeResolver.php +++ b/src/Type/Doctrine/HydrationModeReturnTypeResolver.php @@ -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; @@ -21,7 +22,7 @@ class HydrationModeReturnTypeResolver public function getMethodReturnTypeForHydrationMode( string $methodName, - int $hydrationMode, + Type $hydrationMode, Type $queryKeyType, Type $queryResultType, ?ObjectManager $objectManager @@ -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: diff --git a/src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php b/src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php index ef638cad..091e3716 100644 --- a/src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php +++ b/src/Type/Doctrine/Query/QueryResultDynamicReturnTypeExtension.php @@ -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; @@ -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() diff --git a/tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php b/tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php index f78b81a4..b9d02c85 100644 --- a/tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php +++ b/tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php @@ -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