Skip to content

Commit 35ca80b

Browse files
committed
Fix query flags for lower-case functions
Signed-off-by: Maximilian Krög <[email protected]>
1 parent f136374 commit 35ca80b

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,11 @@ parameters:
955955
count: 1
956956
path: src/Utils/Query.php
957957

958+
-
959+
message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#"
960+
count: 1
961+
path: src/Utils/Query.php
962+
958963
-
959964
message: "#^Cannot access offset 'value' on mixed\\.$#"
960965
count: 3

psalm-baseline.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,9 @@
13421342
<InvalidNullableReturnType occurrences="1">
13431343
<code>int</code>
13441344
</InvalidNullableReturnType>
1345-
<MixedArgument occurrences="1">
1345+
<MixedArgument occurrences="2">
13461346
<code>$expr</code>
1347+
<code>$expr-&gt;function</code>
13471348
</MixedArgument>
13481349
<MixedArrayOffset occurrences="2">
13491350
<code>$clauses[$token-&gt;keyword]</code>

src/Utils/Query.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use function count;
3737
use function in_array;
3838
use function is_string;
39+
use function strtoupper;
3940
use function trim;
4041

4142
/**
@@ -317,9 +318,10 @@ private static function getFlagsSelect($statement, $flags)
317318

318319
foreach ($expressions as $expr) {
319320
if (! empty($expr->function)) {
320-
if ($expr->function === 'COUNT') {
321+
$function = strtoupper($expr->function);
322+
if ($function === 'COUNT') {
321323
$flags['is_count'] = true;
322-
} elseif (in_array($expr->function, static::$FUNCTIONS)) {
324+
} elseif (in_array($function, static::$FUNCTIONS, true)) {
323325
$flags['is_func'] = true;
324326
}
325327
}

tests/Utils/QueryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ public function getFlagsProvider(): array
181181
'querytype' => 'SELECT',
182182
],
183183
],
184+
[
185+
'SELECT count(*) FROM tbl',
186+
[
187+
'is_count' => true,
188+
'is_select' => true,
189+
'select_from' => true,
190+
'querytype' => 'SELECT',
191+
],
192+
],
193+
[
194+
'SELECT sum(*) FROM tbl',
195+
[
196+
'is_func' => true,
197+
'is_select' => true,
198+
'select_from' => true,
199+
'querytype' => 'SELECT',
200+
],
201+
],
184202
[
185203
'SELECT (SELECT "foo")',
186204
[

0 commit comments

Comments
 (0)