diff --git a/.phpstan-dba-mysqli.cache b/.phpstan-dba-mysqli.cache index 853efb155..888331abd 100644 --- a/.phpstan-dba-mysqli.cache +++ b/.phpstan-dba-mysqli.cache @@ -1,6 +1,6 @@ 'v12-new-cache5', - 'schemaHash' => 'f94fe2b38e193ad685009d3f4942f476', + 'schemaHash' => '72813316a311d2e2b9384c458247d011', 'records' => array ( 'SELECT @@ -54,94 +54,6 @@ ), ), ), - 'SELECT * FROM ada' => - array ( - 'result' => - array ( - 3 => - array ( - 'type-description' => 'array{adaid: int<-32768, 32767>, gesperrt: int<-128, 127>, email: string, freigabe1u1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT * FROM ak' => - array ( - 'result' => - array ( - 3 => - array ( - 'type-description' => 'array{akid: int<-2147483648, 2147483647>, eladaid: int<-2147483648, 2147483647>|null, eadavk: numeric-string}', - ), - ), - ), - 'SELECT adaid FROM ada WHERE adaid IN (\'1\')' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}', - ), - ), - ), - 'SELECT adaid FROM ada WHERE adaid IN (\'1\') AND email LIKE \'1970-01-01\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}', - ), - ), - ), - 'SELECT adaid FROM ada WHERE email LIKE \'%questions ?%\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}', - ), - ), - ), - 'SELECT adaid FROM ada WHERE email LIKE \'hello?%\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}', - ), - ), - ), - 'SELECT akid FROM ak WHERE akid IN (\'1\')' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{akid: int<-2147483648, 2147483647>, 0: int<-2147483648, 2147483647>}', - ), - ), - ), - 'SELECT akid FROM ak WHERE id IN (\'1\')' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'Unknown column \'id\' in \'where clause\'', - 'code' => 1054, - )), - ), - 'SELECT akid FROM table WHERE id IN (\'1\')' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'table WHERE id IN (\'1\') LIMIT 0\' at line 1 - -Simulated query: SELECT akid FROM table WHERE id IN (\'1\') LIMIT 0', - 'code' => 1064, - )), - ), 'SELECT column_name, column_default, is_nullable FROM information_schema.columns WHERE table_name = \'1970-01-01\'' => @@ -154,158 +66,6 @@ Simulated query: SELECT akid FROM table WHERE id IN (\'1\') LIMIT 0', ), ), ), - 'SELECT email adaid - WHERE gesperrt = \'1\' AND email LIKE \'%@example.com\' - FROM ada - LIMIT 1' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'FROM ada LIMIT 0\' at line 3 - -Simulated query: SELECT email adaid - WHERE gesperrt = \'1\' AND email LIKE \'%@example.com\' - FROM ada LIMIT 0', - 'code' => 1064, - )), - ), - 'SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'freigabe1u1 FROM ada LIMIT 0\' at line 1 - -Simulated query: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT 0', - 'code' => 1064, - )), - ), - 'SELECT email adaid gesperrt freigabe1u1 FROM ada' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'gesperrt freigabe1u1 FROM ada LIMIT 0\' at line 1 - -Simulated query: SELECT email adaid gesperrt freigabe1u1 FROM ada LIMIT 0', - 'code' => 1064, - )), - ), - 'SELECT email, adaid FROM ada WHERE email = \'a\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid FROM ada' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid FROM ada WHERE adaid = \'1\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid FROM ada WHERE adaid=1' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid FROM ada WHERE email = \'test@example.org\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid FROM ada WHERE email=\'test@example.org\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = \'1\'' => - array ( - 'result' => - array ( - 5 => - array ( - 'type-description' => 'array{email: string, 0: string, adaid: int<-32768, 32767>, 1: int<-32768, 32767>, gesperrt: int<-128, 127>, 2: int<-128, 127>, freigabe1u1: int<-32768, 32767>, 3: int<-32768, 32767>}', - ), - ), - ), - 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE asdsa=\'1\'' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'Unknown column \'asdsa\' in \'where clause\'', - 'code' => 1054, - )), - ), - 'SELECT id FROM table WHERE a=\'1970-01-01\' AND err-or id IN (\'1\')' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'table WHERE a=\'1970-01-01\' AND err-or id IN (\'1\') LIMIT 0\' at line 1 - -Simulated query: SELECT id FROM table WHERE a=\'1970-01-01\' AND err-or id IN (\'1\') LIMIT 0', - 'code' => 1064, - )), - ), - 'SELECT id FROM table WHERE err-or id IN (\'1\')' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'table WHERE err-or id IN (\'1\') LIMIT 0\' at line 1 - -Simulated query: SELECT id FROM table WHERE err-or id IN (\'1\') LIMIT 0', - 'code' => 1064, - )), - ), - 'SELECT id FROM table WHERE id IN (\'1\')' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'table WHERE id IN (\'1\') LIMIT 0\' at line 1 - -Simulated query: SELECT id FROM table WHERE id IN (\'1\') LIMIT 0', - 'code' => 1064, - )), - ), - 'Select * from ada - where adakzid = 15' => - array ( - 'error' => - \staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'Unknown column \'adakzid\' in \'where clause\'', - 'code' => 1054, - )), - ), ), 'runtimeConfig' => array ( diff --git a/.phpstan-dba-pdo-mysql.cache b/.phpstan-dba-pdo-mysql.cache index 7c82ddc1d..888331abd 100644 --- a/.phpstan-dba-pdo-mysql.cache +++ b/.phpstan-dba-pdo-mysql.cache @@ -1,6 +1,6 @@ 'v12-new-cache5', - 'schemaHash' => 'f94fe2b38e193ad685009d3f4942f476', + 'schemaHash' => '72813316a311d2e2b9384c458247d011', 'records' => array ( 'SELECT diff --git a/src/Rules/QueryPlanAnalyzerRule.php b/src/Rules/QueryPlanAnalyzerRule.php index 4a1b46d3d..43b6eba3b 100644 --- a/src/Rules/QueryPlanAnalyzerRule.php +++ b/src/Rules/QueryPlanAnalyzerRule.php @@ -8,6 +8,9 @@ use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; +use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; @@ -30,7 +33,7 @@ final class QueryPlanAnalyzerRule implements Rule /** * @var list */ - private array $classMethods; + public array $classMethods; private ReflectionProvider $reflectionProvider; @@ -56,6 +59,15 @@ public function processNode(Node $callLike, Scope $scope): array } $methodReflection = $scope->getMethodReflection($scope->getType($callLike->var), $callLike->name->toString()); + } elseif ($callLike instanceof StaticCall) { + if (! $callLike->name instanceof Identifier) { + return []; + } + if (! $callLike->class instanceof Name) { + return []; + } + $classType = $scope->resolveTypeByName($callLike->class); + $methodReflection = $scope->getMethodReflection($classType, $callLike->name->toString()); } elseif ($callLike instanceof New_) { if (! $callLike->class instanceof FullyQualified) { return []; @@ -105,7 +117,7 @@ public function processNode(Node $callLike, Scope $scope): array } /** - * @param MethodCall|New_ $callLike + * @param MethodCall|StaticCall|New_ $callLike * * @return list */ diff --git a/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php b/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php index 432d1e839..68774e6ed 100644 --- a/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php +++ b/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php @@ -8,6 +8,9 @@ use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; +use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; @@ -57,6 +60,15 @@ public function processNode(Node $callLike, Scope $scope): array } $methodReflection = $scope->getMethodReflection($scope->getType($callLike->var), $callLike->name->toString()); + } elseif ($callLike instanceof StaticCall) { + if (! $callLike->name instanceof Identifier) { + return []; + } + if (! $callLike->class instanceof Name) { + return []; + } + $classType = $scope->resolveTypeByName($callLike->class); + $methodReflection = $scope->getMethodReflection($classType, $callLike->name->toString()); } elseif ($callLike instanceof New_) { if (! $callLike->class instanceof FullyQualified) { return []; @@ -96,7 +108,7 @@ public function processNode(Node $callLike, Scope $scope): array } /** - * @param MethodCall|New_ $callLike + * @param MethodCall|StaticCall|New_ $callLike * * @return list */ diff --git a/src/Rules/SyntaxErrorInQueryMethodRule.php b/src/Rules/SyntaxErrorInQueryMethodRule.php index 651375798..457515f42 100644 --- a/src/Rules/SyntaxErrorInQueryMethodRule.php +++ b/src/Rules/SyntaxErrorInQueryMethodRule.php @@ -5,7 +5,11 @@ namespace staabm\PHPStanDba\Rules; use PhpParser\Node; +use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; @@ -15,7 +19,7 @@ use staabm\PHPStanDba\UnresolvableQueryException; /** - * @implements Rule + * @implements Rule * * @see SyntaxErrorInQueryMethodRuleTest */ @@ -39,16 +43,29 @@ public function __construct(array $classMethods, ReflectionProvider $reflectionP public function getNodeType(): string { - return MethodCall::class; + return CallLike::class; } - public function processNode(Node $node, Scope $scope): array + public function processNode(Node $callLike, Scope $scope): array { - if (! $node->name instanceof Node\Identifier) { + if ($callLike instanceof MethodCall) { + if (! $callLike->name instanceof Identifier) { + return []; + } + $methodReflection = $scope->getMethodReflection($scope->getType($callLike->var), $callLike->name->toString()); + } elseif ($callLike instanceof StaticCall) { + if (! $callLike->name instanceof Identifier) { + return []; + } + if (! $callLike->class instanceof Name) { + return []; + } + $classType = $scope->resolveTypeByName($callLike->class); + $methodReflection = $scope->getMethodReflection($classType, $callLike->name->toString()); + } else { return []; } - $methodReflection = $scope->getMethodReflection($scope->getType($node->var), $node->name->toString()); if (null === $methodReflection) { return []; } @@ -79,7 +96,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - $args = $node->getArgs(); + $args = $callLike->getArgs(); if (! \array_key_exists($queryArgPosition, $args)) { return []; @@ -98,13 +115,13 @@ public function processNode(Node $node, Scope $scope): array $queryError = $queryReflection->validateQueryString($queryString); if (null !== $queryError) { return [ - RuleErrorBuilder::message($queryError->asRuleMessage())->identifier('dba.syntaxError')->line($node->getStartLine())->build(), + RuleErrorBuilder::message($queryError->asRuleMessage())->identifier('dba.syntaxError')->line($callLike->getStartLine())->build(), ]; } } } catch (UnresolvableQueryException $exception) { return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->identifier('dba.unresolvableQuery')->line($node->getStartLine())->build(), + RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->identifier('dba.unresolvableQuery')->line($callLike->getStartLine())->build(), ]; } diff --git a/tests/default/Fixture/StaticDatabase.php b/tests/default/Fixture/StaticDatabase.php new file mode 100644 index 000000000..d87d3328b --- /dev/null +++ b/tests/default/Fixture/StaticDatabase.php @@ -0,0 +1,28 @@ +debugMode($this->debugMode); QueryReflection::getRuntimeConfiguration()->analyzeQueryPlans($this->numberOfAllowedUnindexedReads, $this->numberOfRowsNotRequiringIndex); - return self::getContainer()->getByType(QueryPlanAnalyzerRule::class); + $rule = self::getContainer()->getByType(QueryPlanAnalyzerRule::class); + $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::query#0'; + $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::executeQuery#0'; + return $rule; } public static function getAdditionalConfigFiles(): array @@ -94,6 +97,16 @@ public function testNotUsingIndex(): void 28, $tip, ], + [ + "Query is not using an index on table 'ada'." . $proposal, + 78, + $tip, + ], + [ + "Query is not using an index on table 'ada'." . $proposal, + 79, + $tip, + ], ]); } @@ -160,6 +173,16 @@ public function testNotUsingIndexInDebugMode(): void 73, UnresolvableQueryStringTypeException::getTip(), ], + [ + "Query is not using an index on table 'ada'." . $proposal . "\n\nSimulated query: EXPLAIN SELECT * FROM `ada` WHERE email = 'test@example.com'", + 78, + $tip, + ], + [ + "Query is not using an index on table 'ada'." . $proposal . "\n\nSimulated query: EXPLAIN SELECT *,adaid FROM `ada` WHERE email = 'test@example.com'", + 79, + $tip, + ], ]); } } diff --git a/tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php b/tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php index c5483e732..8826cfb6c 100644 --- a/tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php +++ b/tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php @@ -21,6 +21,8 @@ protected function getRule(): Rule $rule = self::getContainer()->getByType(SyntaxErrorInPreparedStatementMethodRule::class); $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\Connection::preparedQuery'; $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\PreparedStatement::__construct'; + $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::preparedQuery'; + $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::prepare'; return $rule; } @@ -92,6 +94,14 @@ public function testSyntaxErrorInQueryRule(): void 'Query expects placeholder :freigabe1u1, but it is missing from values given.', 325, ], + [ + "Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).", + 388, + ], + [ + $error, + 389, + ], ]; } elseif (PdoPgSqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) { $expectedErrors = [ @@ -171,6 +181,18 @@ public function testSyntaxErrorInQueryRule(): void 'Query expects placeholder :freigabe1u1, but it is missing from values given.', 325, ], + [ + 'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1" +LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT... + ^ (42601).', + 388, + ], + [ + 'Query error: SQLSTATE[42703]: Undefined column: 7 ERROR: column "asdsa" does not exist +LINE 1: ...mail, adaid, gesperrt, freigabe1u1 FROM ada WHERE asdsa=\'1\' ... + ^ (42703).', + 389, + ], ]; } elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) { if ('mariadb' === $_ENV['DBA_PLATFORM']) { @@ -230,6 +252,14 @@ public function testSyntaxErrorInQueryRule(): void 'Query expects placeholder :freigabe1u1, but it is missing from values given.', 325, ], + [ + "Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).", + 388, + ], + [ + "Query error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'asdsa' in 'where clause' (42S22).", + 389, + ], ]; } else { throw new \RuntimeException('Unsupported DBA_REFLECTOR ' . getenv('DBA_REFLECTOR')); diff --git a/tests/rules/SyntaxErrorInQueryMethodRuleTest.php b/tests/rules/SyntaxErrorInQueryMethodRuleTest.php index d2a4eb1dc..a401bb4de 100644 --- a/tests/rules/SyntaxErrorInQueryMethodRuleTest.php +++ b/tests/rules/SyntaxErrorInQueryMethodRuleTest.php @@ -20,7 +20,10 @@ class SyntaxErrorInQueryMethodRuleTest extends RuleTestCase { protected function getRule(): Rule { - return self::getContainer()->getByType(SyntaxErrorInQueryMethodRule::class); + $rule = self::getContainer()->getByType(SyntaxErrorInQueryMethodRule::class); + $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::query#0'; + $rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::prepare#0'; + return $rule; } public static function getAdditionalConfigFiles(): array @@ -114,6 +117,14 @@ public function testSyntaxErrorInQueryRule(): void "Query error: Table 'phpstan_dba.adasfd' doesn't exist (1146).", 138, ], + [ + "Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).", + 154, + ], + [ + "Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).", + 155, + ], ]; } elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) { if ('mariadb' === $_ENV['DBA_PLATFORM']) { @@ -185,6 +196,14 @@ public function testSyntaxErrorInQueryRule(): void "Query error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'phpstan_dba.adasfd' doesn't exist (42S02).", 138, ], + [ + "Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).", + 154, + ], + [ + "Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).", + 155, + ], ]; } elseif (PdoPgSqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) { $expected = [ @@ -296,6 +315,18 @@ public function testSyntaxErrorInQueryRule(): void ^ (42601).', 138, ], + [ + 'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1" +LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT... + ^ (42601).', + 154, + ], + [ + 'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1" +LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT... + ^ (42601).', + 155, + ], ]; } else { throw new \RuntimeException('Unsupported DBA_REFLECTOR ' . getenv('DBA_REFLECTOR')); diff --git a/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache b/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache index d6ab8e947..3d0c8527b 100644 --- a/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache +++ b/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache @@ -55,6 +55,14 @@ Simulated query: EXPLAIN REPLACE INTO `ada` SET email="test" WHERE adaid = 1', 'code' => 1146, )), ), + 'EXPLAIN UPDATE package SET indexedAt=\'1970-01-01\' WHERE id IN (\'1\') AND (indexedAt IS NULL OR indexedAt <= crawledAt)' => + array ( + 'error' => + \staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'Table \'phpstan_dba.package\' doesn\'t exist', + 'code' => 1146, + )), + ), 'EXPLAIN UPDATE package SET indexedAt=\'1970-01-01\' WHERE id IN (NULL) AND (indexedAt IS NULL OR indexedAt <= crawledAt)' => array ( 'error' => @@ -416,6 +424,14 @@ Simulated query: SELECT FROM WHERE LIMIT 0', 'code' => 1064, )), ), + 'SELECT email, adaid GROUP BY xy FROM ada LIMIT 1' => + array ( + 'error' => + \staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'FROM ada LIMIT 0\' at line 1', + 'code' => 1064, + )), + ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => array ( 'result' => diff --git a/tests/rules/data/query-plan-analyzer.php b/tests/rules/data/query-plan-analyzer.php index ba4e69e64..5ac10508c 100644 --- a/tests/rules/data/query-plan-analyzer.php +++ b/tests/rules/data/query-plan-analyzer.php @@ -72,4 +72,10 @@ public function bug442(Connection $conn, string $table) $query = "SELECT email, adaid FROM `$table` WHERE adaid = ?"; $conn->fetchAssociative($query, [1]); } + + public function staticCallTests(): void + { + \staabm\PHPStanDba\Tests\Fixture\StaticDatabase::query("SELECT * FROM `ada` WHERE email = 'test@example.com';"); + \staabm\PHPStanDba\Tests\Fixture\StaticDatabase::executeQuery("SELECT *,adaid FROM `ada` WHERE email = 'test@example.com';"); + } } diff --git a/tests/rules/data/syntax-error-in-prepared-statement.php b/tests/rules/data/syntax-error-in-prepared-statement.php index 537d22f72..63b2a2fd9 100644 --- a/tests/rules/data/syntax-error-in-prepared-statement.php +++ b/tests/rules/data/syntax-error-in-prepared-statement.php @@ -382,4 +382,10 @@ protected function conditionalUnnamedPlaceholder(Connection $connection, array $ $connection->preparedQuery($query, $values); } + + public function staticCallPreparedStatementTests(): void + { + \staabm\PHPStanDba\Tests\Fixture\StaticDatabase::preparedQuery('SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada', []); + \staabm\PHPStanDba\Tests\Fixture\StaticDatabase::prepare('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE asdsa=?', [1]); + } } diff --git a/tests/rules/data/syntax-error-in-query-method.php b/tests/rules/data/syntax-error-in-query-method.php index 74f93c4f2..ac996e123 100644 --- a/tests/rules/data/syntax-error-in-query-method.php +++ b/tests/rules/data/syntax-error-in-query-method.php @@ -149,4 +149,9 @@ public function bug458(PDO $pdo) $pdo->query('SELECT * FROM ' . $table . ' LIMIT 1'); } + public function staticCallQueryTests(): void + { + \staabm\PHPStanDba\Tests\Fixture\StaticDatabase::query('SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada', PDO::FETCH_ASSOC); + \staabm\PHPStanDba\Tests\Fixture\StaticDatabase::prepare('SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada'); + } }