Skip to content

Commit cfd85c3

Browse files
committed
Report invalid query after simulation as unresolvable
1 parent 2b9b044 commit cfd85c3

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/QueryReflection/QueryReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use staabm\PHPStanDba\SchemaReflection\SchemaReflection;
3535
use staabm\PHPStanDba\SqlAst\ParserInference;
3636
use staabm\PHPStanDba\UnresolvableQueryException;
37+
use staabm\PHPStanDba\UnresolvableQueryInvalidAfterSimulationException;
3738

3839
final class QueryReflection
3940
{
@@ -292,6 +293,10 @@ public function resolveQueryStrings(Expr $queryExpr, Scope $scope): iterable
292293
$error = $this->validateQueryString($normalizedQuery);
293294
if ($error === null) {
294295
yield $normalizedQuery;
296+
} else {
297+
if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) {
298+
throw new UnresolvableQueryInvalidAfterSimulationException('Seems the query is too dynamic to be resolved by query simulation');
299+
}
295300
}
296301
}
297302
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace staabm\PHPStanDba;
6+
7+
/**
8+
* @api
9+
*/
10+
final class UnresolvableQueryInvalidAfterSimulationException extends UnresolvableQueryException
11+
{
12+
public static function getTip(): string
13+
{
14+
return 'Consider to simplify the query string construction.';
15+
}
16+
}

tests/rules/UnresolvableQueryMethodRuleTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Testing\RuleTestCase;
99
use staabm\PHPStanDba\QueryReflection\QueryReflection;
1010
use staabm\PHPStanDba\Rules\SyntaxErrorInQueryMethodRule;
11+
use staabm\PHPStanDba\UnresolvableQueryInvalidAfterSimulationException;
1112
use staabm\PHPStanDba\UnresolvableQueryMixedTypeException;
1213
use staabm\PHPStanDba\UnresolvableQueryStringTypeException;
1314

@@ -76,6 +77,12 @@ public function testBug548(): void
7677

7778
public function testBug547(): void
7879
{
79-
$this->analyse([__DIR__ . '/data/bug-547.php'], []);
80+
$this->analyse([__DIR__ . '/data/bug-547.php'], [
81+
[
82+
'Unresolvable Query: Seems the query is too dynamic to be resolved by query simulation.',
83+
10,
84+
UnresolvableQueryInvalidAfterSimulationException::getTip(),
85+
],
86+
]);
8087
}
8188
}

0 commit comments

Comments
 (0)