Skip to content

Commit

Permalink
Merge pull request #590 from kamil-tekiela/Fix-keyword-parsing
Browse files Browse the repository at this point in the history
Fix keyword parsing
  • Loading branch information
MauricioFauth authored Oct 25, 2024
2 parents bc9ce73 + 7252aca commit abe850f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -960,11 +960,6 @@ 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
6 changes: 5 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,9 @@
<DocblockTypeContradiction occurrences="1">
<code>! ($statement instanceof SelectStatement)</code>
</DocblockTypeContradiction>
<MixedArrayOffset occurrences="1">
<code>$tables[$thisDb][$expr-&gt;table]</code>
</MixedArrayOffset>
<PossiblyNullArrayOffset occurrences="1">
<code>$tables[$thisDb]</code>
</PossiblyNullArrayOffset>
Expand All @@ -1348,9 +1351,10 @@
<code>$expr</code>
<code>$expr-&gt;function</code>
</MixedArgument>
<MixedArrayOffset occurrences="2">
<MixedArrayOffset occurrences="3">
<code>$clauses[$token-&gt;keyword]</code>
<code>$clauses[$token-&gt;keyword]</code>
<code>$tableAliases[$expr-&gt;table]</code>
</MixedArrayOffset>
<MixedArrayTypeCoercion occurrences="2">
<code>$clauses[$token-&gt;keyword]</code>
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

// Conditions are delimited by logical operators.
if (in_array($token->value, static::$DELIMITERS, true)) {
if (
($token->type === Token::TYPE_KEYWORD || $token->type === Token::TYPE_OPERATOR)
&& in_array($token->value, static::$DELIMITERS, true)
) {
if ($betweenBefore && ($token->value === 'AND')) {
// The syntax of keyword `BETWEEN` is hard-coded.
$betweenBefore = false;
Expand Down
12 changes: 12 additions & 0 deletions tests/Components/ConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ public function testParseBetween(): void
$this->assertEquals($component[1]->expr, 'OR');
$this->assertEquals($component[2]->expr, '(id BETWEEN 30 AND 40)');
}

public function testParseAnd(): void
{
$component = Condition::parse(
new Parser(),
$this->getTokensList("`col` LIKE 'AND'")
);
$this->assertEquals(
"`col` LIKE 'AND'",
Condition::build($component)
);
}
}

0 comments on commit abe850f

Please sign in to comment.