Skip to content

Commit 8bede0a

Browse files
committed
Report invalid query after simulation as unresolvable
1 parent 31e91bb commit 8bede0a

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
{
@@ -286,6 +287,10 @@ public function resolveQueryStrings(Expr $queryExpr, Scope $scope): iterable
286287
$error = $this->validateQueryString($normalizedQuery);
287288
if ($error === null) {
288289
yield $normalizedQuery;
290+
} else {
291+
if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) {
292+
throw new UnresolvableQueryInvalidAfterSimulationException('Seems the query is too dynamic to be resolved by query simulation');
293+
}
289294
}
290295
}
291296
}
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)