Skip to content

Commit

Permalink
Fix query flags for lower-case functions
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Krög <[email protected]>
  • Loading branch information
MoonE committed Jul 3, 2024
1 parent f136374 commit a4f7166
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ parameters:
count: 1
path: src/Utils/Query.php

-
message: "#^Parameter \\#1 \\$string of function strtoupper expects string, mixed given\\.$#"
count: 1
path: src/Utils/Query.php

-
message: "#^Cannot access offset 'value' on mixed\\.$#"
count: 3
Expand Down
3 changes: 2 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,9 @@
<InvalidNullableReturnType occurrences="1">
<code>int</code>
</InvalidNullableReturnType>
<MixedArgument occurrences="1">
<MixedArgument occurrences="2">
<code>$expr</code>
<code>$expr-&gt;function</code>
</MixedArgument>
<MixedArrayOffset occurrences="2">
<code>$clauses[$token-&gt;keyword]</code>
Expand Down
6 changes: 4 additions & 2 deletions src/Utils/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use function count;
use function in_array;
use function is_string;
use function strtoupper;
use function trim;

/**
Expand Down Expand Up @@ -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);

Check failure on line 321 in src/Utils/Query.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.4)

Parameter #1 $str of function strtoupper expects string, mixed given.
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;
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Utils/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")',
[
Expand Down

0 comments on commit a4f7166

Please sign in to comment.