Skip to content

Commit abe850f

Browse files
Merge pull request #590 from kamil-tekiela/Fix-keyword-parsing
Fix keyword parsing
2 parents bc9ce73 + 7252aca commit abe850f

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

phpstan-baseline.neon

-5
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,6 @@ parameters:
960960
count: 1
961961
path: src/Utils/Query.php
962962

963-
-
964-
message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#"
965-
count: 1
966-
path: src/Utils/Query.php
967-
968963
-
969964
message: "#^Cannot access offset 'value' on mixed\\.$#"
970965
count: 3

psalm-baseline.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,9 @@
13361336
<DocblockTypeContradiction occurrences="1">
13371337
<code>! ($statement instanceof SelectStatement)</code>
13381338
</DocblockTypeContradiction>
1339+
<MixedArrayOffset occurrences="1">
1340+
<code>$tables[$thisDb][$expr-&gt;table]</code>
1341+
</MixedArrayOffset>
13391342
<PossiblyNullArrayOffset occurrences="1">
13401343
<code>$tables[$thisDb]</code>
13411344
</PossiblyNullArrayOffset>
@@ -1348,9 +1351,10 @@
13481351
<code>$expr</code>
13491352
<code>$expr-&gt;function</code>
13501353
</MixedArgument>
1351-
<MixedArrayOffset occurrences="2">
1354+
<MixedArrayOffset occurrences="3">
13521355
<code>$clauses[$token-&gt;keyword]</code>
13531356
<code>$clauses[$token-&gt;keyword]</code>
1357+
<code>$tableAliases[$expr-&gt;table]</code>
13541358
</MixedArrayOffset>
13551359
<MixedArrayTypeCoercion occurrences="2">
13561360
<code>$clauses[$token-&gt;keyword]</code>

src/Components/Condition.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
146146
}
147147

148148
// Conditions are delimited by logical operators.
149-
if (in_array($token->value, static::$DELIMITERS, true)) {
149+
if (
150+
($token->type === Token::TYPE_KEYWORD || $token->type === Token::TYPE_OPERATOR)
151+
&& in_array($token->value, static::$DELIMITERS, true)
152+
) {
150153
if ($betweenBefore && ($token->value === 'AND')) {
151154
// The syntax of keyword `BETWEEN` is hard-coded.
152155
$betweenBefore = false;

tests/Components/ConditionTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ public function testParseBetween(): void
2626
$this->assertEquals($component[1]->expr, 'OR');
2727
$this->assertEquals($component[2]->expr, '(id BETWEEN 30 AND 40)');
2828
}
29+
30+
public function testParseAnd(): void
31+
{
32+
$component = Condition::parse(
33+
new Parser(),
34+
$this->getTokensList("`col` LIKE 'AND'")
35+
);
36+
$this->assertEquals(
37+
"`col` LIKE 'AND'",
38+
Condition::build($component)
39+
);
40+
}
2941
}

0 commit comments

Comments
 (0)