Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \\$str 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);
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