Skip to content

Commit d8e30bc

Browse files
committed
Merge #564 - Fix query flags for lower-case functions
Pull-request: #564 Signed-off-by: William Desportes <[email protected]>
2 parents 7c4a54a + 35ca80b commit d8e30bc

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
@@ -950,6 +950,11 @@ parameters:
950950
count: 1
951951
path: src/Utils/Query.php
952952

953+
-
954+
message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#"
955+
count: 1
956+
path: src/Utils/Query.php
957+
953958
-
954959
message: "#^Cannot access offset 'value' on mixed\\.$#"
955960
count: 3

psalm-baseline.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,9 @@
13361336
<InvalidNullableReturnType occurrences="1">
13371337
<code>int</code>
13381338
</InvalidNullableReturnType>
1339-
<MixedArgument occurrences="1">
1339+
<MixedArgument occurrences="2">
13401340
<code>$expr</code>
1341+
<code>$expr-&gt;function</code>
13411342
</MixedArgument>
13421343
<MixedArrayOffset occurrences="2">
13431344
<code>$clauses[$token-&gt;keyword]</code>

src/Utils/Query.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use function count;
3838
use function in_array;
3939
use function is_string;
40+
use function strtoupper;
4041
use function trim;
4142

4243
/**
@@ -318,9 +319,10 @@ private static function getFlagsSelect($statement, $flags)
318319

319320
foreach ($expressions as $expr) {
320321
if (! empty($expr->function)) {
321-
if ($expr->function === 'COUNT') {
322+
$function = strtoupper($expr->function);
323+
if ($function === 'COUNT') {
322324
$flags['is_count'] = true;
323-
} elseif (in_array($expr->function, static::$FUNCTIONS)) {
325+
} elseif (in_array($function, static::$FUNCTIONS, true)) {
324326
$flags['is_func'] = true;
325327
}
326328
}

tests/Utils/QueryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ public static 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)