Skip to content

Commit 8751661

Browse files
authored
Prevent endless loop in QuerySimulation (#763)
1 parent c7c417b commit 8751661

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/QueryReflection/QuerySimulation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Type\ErrorType;
1010
use PHPStan\Type\IntersectionType;
1111
use PHPStan\Type\MixedType;
12+
use PHPStan\Type\NeverType;
1213
use PHPStan\Type\ObjectType;
1314
use PHPStan\Type\StringType;
1415
use PHPStan\Type\Type;
@@ -30,6 +31,10 @@ final class QuerySimulation
3031
*/
3132
public static function simulateParamValueType(Type $paramType, bool $preparedParam): ?string
3233
{
34+
if ($paramType instanceof NeverType) {
35+
return null;
36+
}
37+
3338
if ($paramType instanceof ConstantScalarType) {
3439
return (string) $paramType->getValue();
3540
}

tests/default/QuerySimulationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
88
use PHPStan\Type\FloatType;
99
use PHPStan\Type\IntegerType;
10+
use PHPStan\Type\NeverType;
1011
use PHPStan\Type\StringType;
1112
use PHPUnit\Framework\TestCase;
1213
use staabm\PHPStanDba\QueryReflection\QuerySimulation;
@@ -44,6 +45,17 @@ public function testIntersectionTypeMix()
4445
self::assertNotNull($simulatedValue);
4546
}
4647

48+
/**
49+
* Prevent endless loop.
50+
*
51+
* see https://github.com/yakamara/ydeploy/pull/101
52+
*/
53+
public function testNeverType()
54+
{
55+
self::assertNull(QuerySimulation::simulateParamValueType(new NeverType(), true));
56+
self::assertNull(QuerySimulation::simulateParamValueType(new NeverType(), false));
57+
}
58+
4759
/**
4860
* @dataProvider provideQueriesWithComments
4961
*/

0 commit comments

Comments
 (0)