From af85abd51fa74ee39bf6e96e9005105a40174344 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 15 Oct 2024 17:49:43 +0100 Subject: [PATCH 1/2] Fix keyword parsing Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 5 ----- psalm-baseline.xml | 6 +++++- src/Components/Condition.php | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 24e1cddc..cc728114 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index ed08d689..7854c67b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1336,6 +1336,9 @@ ! ($statement instanceof SelectStatement) + + $tables[$thisDb][$expr->table] + $tables[$thisDb] @@ -1348,9 +1351,10 @@ $expr $expr->function - + $clauses[$token->keyword] $clauses[$token->keyword] + $tableAliases[$expr->table] $clauses[$token->keyword] diff --git a/src/Components/Condition.php b/src/Components/Condition.php index e29684ae..38174570 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -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; From 7252acaa6dedfb4d2666eb8e68edf972e43ba99c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 20 Oct 2024 13:01:33 +0100 Subject: [PATCH 2/2] Add unit test Signed-off-by: Kamil Tekiela --- tests/Components/ConditionTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Components/ConditionTest.php b/tests/Components/ConditionTest.php index 909e4d1c..4ff86093 100644 --- a/tests/Components/ConditionTest.php +++ b/tests/Components/ConditionTest.php @@ -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) + ); + } }