diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 878a5112..59f22a08 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -955,6 +955,11 @@ parameters: count: 1 path: src/Utils/Query.php + - + message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#" + count: 1 + path: src/Utils/Query.php + - message: "#^Cannot access offset 'value' on mixed\\.$#" count: 3 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 80d5bdb4..f3e22360 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1342,8 +1342,9 @@ int - + $expr + $expr->function $clauses[$token->keyword] diff --git a/src/Utils/Query.php b/src/Utils/Query.php index f5b5320b..8ebd239e 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -36,6 +36,7 @@ use function count; use function in_array; use function is_string; +use function strtoupper; use function trim; /** @@ -317,9 +318,10 @@ private static function getFlagsSelect($statement, $flags) foreach ($expressions as $expr) { if (! empty($expr->function)) { - if ($expr->function === 'COUNT') { + $function = strtoupper($expr->function); + if ($function === 'COUNT') { $flags['is_count'] = true; - } elseif (in_array($expr->function, static::$FUNCTIONS)) { + } elseif (in_array($function, static::$FUNCTIONS, true)) { $flags['is_func'] = true; } } diff --git a/tests/Utils/QueryTest.php b/tests/Utils/QueryTest.php index 62981ed0..53f34c7a 100644 --- a/tests/Utils/QueryTest.php +++ b/tests/Utils/QueryTest.php @@ -181,6 +181,24 @@ public function getFlagsProvider(): array 'querytype' => 'SELECT', ], ], + [ + 'SELECT count(*) FROM tbl', + [ + 'is_count' => true, + 'is_select' => true, + 'select_from' => true, + 'querytype' => 'SELECT', + ], + ], + [ + 'SELECT sum(*) FROM tbl', + [ + 'is_func' => true, + 'is_select' => true, + 'select_from' => true, + 'querytype' => 'SELECT', + ], + ], [ 'SELECT (SELECT "foo")', [