diff --git a/src/QueryReflection/QueryReflection.php b/src/QueryReflection/QueryReflection.php index cb97c5ed1..2e67033e4 100644 --- a/src/QueryReflection/QueryReflection.php +++ b/src/QueryReflection/QueryReflection.php @@ -34,6 +34,7 @@ use staabm\PHPStanDba\SchemaReflection\SchemaReflection; use staabm\PHPStanDba\SqlAst\ParserInference; use staabm\PHPStanDba\UnresolvableQueryException; +use staabm\PHPStanDba\UnresolvableQueryDynamicFromException; final class QueryReflection { @@ -280,13 +281,7 @@ public function resolveQueryStrings(Expr $queryExpr, Scope $scope): iterable $queryString = $this->resolveQueryExpr($queryExpr, $scope); if (null !== $queryString) { - $normalizedQuery = QuerySimulation::stripComments($this->normalizeQueryString($queryString)); - - // query simulation might lead in a invalid query, skip those - $error = $this->validateQueryString($normalizedQuery); - if ($error === null) { - yield $normalizedQuery; - } + yield QuerySimulation::stripComments($this->normalizeQueryString($queryString)); } } @@ -360,6 +355,13 @@ private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $res $leftString = $this->resolveQueryStringExpr($left, $scope); $rightString = $this->resolveQueryStringExpr($right, $scope); + // queries with a dynamic FROM are not resolvable + if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) { + if (str_ends_with(rtrim($leftString), 'FROM') && is_numeric(trim($rightString, '"\''))) { + throw new UnresolvableQueryDynamicFromException('Seems the query is too dynamic to be resolved by query simulation'); + } + } + if (null === $leftString || null === $rightString) { return null; } diff --git a/src/UnresolvableQueryDynamicFromException.php b/src/UnresolvableQueryDynamicFromException.php new file mode 100644 index 000000000..13b2cf8da --- /dev/null +++ b/src/UnresolvableQueryDynamicFromException.php @@ -0,0 +1,16 @@ +