Skip to content

Commit a2e789f

Browse files
committed
Report invalid query after simulation as unresolvable
1 parent 08a068d commit a2e789f

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
@@ -32,6 +32,7 @@
3232
use staabm\PHPStanDba\SchemaReflection\SchemaReflection;
3333
use staabm\PHPStanDba\SqlAst\ParserInference;
3434
use staabm\PHPStanDba\UnresolvableQueryException;
35+
use staabm\PHPStanDba\UnresolvableQueryInvalidAfterSimulationException;
3536

3637
final class QueryReflection
3738
{
@@ -297,6 +298,10 @@ public function resolveQueryStrings(Expr $queryExpr, Scope $scope): iterable
297298
$error = $this->validateQueryString($normalizedQuery);
298299
if ($error === null) {
299300
yield $normalizedQuery;
301+
} else {
302+
if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) {
303+
throw new UnresolvableQueryInvalidAfterSimulationException('Seems the query is too dynamic to be resolved by query simulation');
304+
}
300305
}
301306
}
302307
}
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,7 +77,13 @@ 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

8289
public function testBug676(): void

0 commit comments

Comments
 (0)