diff --git a/src/QueryReflection/QuerySimulation.php b/src/QueryReflection/QuerySimulation.php index 00ed75a5..1ece4bda 100644 --- a/src/QueryReflection/QuerySimulation.php +++ b/src/QueryReflection/QuerySimulation.php @@ -9,6 +9,7 @@ use PHPStan\Type\ErrorType; use PHPStan\Type\IntersectionType; use PHPStan\Type\MixedType; +use PHPStan\Type\NeverType; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; use PHPStan\Type\Type; @@ -30,6 +31,10 @@ final class QuerySimulation */ public static function simulateParamValueType(Type $paramType, bool $preparedParam): ?string { + if ($paramType instanceof NeverType) { + return null; + } + if ($paramType instanceof ConstantScalarType) { return (string) $paramType->getValue(); } diff --git a/tests/default/QuerySimulationTest.php b/tests/default/QuerySimulationTest.php index 093bcf49..12d2d6fb 100644 --- a/tests/default/QuerySimulationTest.php +++ b/tests/default/QuerySimulationTest.php @@ -7,6 +7,7 @@ use PHPStan\Type\Constant\ConstantArrayTypeBuilder; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; +use PHPStan\Type\NeverType; use PHPStan\Type\StringType; use PHPUnit\Framework\TestCase; use staabm\PHPStanDba\QueryReflection\QuerySimulation; @@ -44,6 +45,17 @@ public function testIntersectionTypeMix() self::assertNotNull($simulatedValue); } + /** + * Prevent endless loop. + * + * see https://github.com/yakamara/ydeploy/pull/101 + */ + public function testNeverType() + { + self::assertNull(QuerySimulation::simulateParamValueType(new NeverType(), true)); + self::assertNull(QuerySimulation::simulateParamValueType(new NeverType(), false)); + } + /** * @dataProvider provideQueriesWithComments */