From 51cfb0fc8ad9b5836e1ffa7fa8550821254de648 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 28 Jul 2025 20:51:55 +0200 Subject: [PATCH] Prevent endless loop in QuerySimulation --- src/QueryReflection/QuerySimulation.php | 5 +++++ tests/default/QuerySimulationTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/QueryReflection/QuerySimulation.php b/src/QueryReflection/QuerySimulation.php index 00ed75a56..1ece4bdad 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 093bcf49e..12d2d6fb3 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 */