diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 49a660025..2494a773f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -170,11 +170,6 @@ parameters: count: 1 path: src/Components/ExpressionArray.php - - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\:\\:\\$name \\(string\\|null\\) does not accept mixed\\.$#" - count: 1 - path: src/Components/FunctionCall.php - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\:\\:\\$parameters \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|null\\) does not accept array\\\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\.$#" count: 1 @@ -560,11 +555,6 @@ parameters: count: 1 path: src/Parser.php - - - message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#" - count: 1 - path: src/Statement.php - - message: "#^Offset 'class' does not exist on array\\{class\\?\\: string, field\\?\\: non\\-empty\\-string, options\\?\\: array\\\\}\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4a0d2b854..b2f6b7683 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -203,9 +203,9 @@ - - $ret->name - + + $token->value + $component @@ -877,9 +877,6 @@ $class::build($this->$field) - - $list->offsetGet($list->idx)->type - Parser::$KEYWORD_PARSERS[$name]['class'] Parser::$KEYWORD_PARSERS[$name]['field'] diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php index e63a90f27..4d6c0ed05 100644 --- a/src/Components/FunctionCall.php +++ b/src/Components/FunctionCall.php @@ -78,6 +78,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = // End of statement. if ($token->type === Token::TYPE_DELIMITER) { + --$list->idx; // Let last token to previous one to avoid "This type of clause was previously parsed." break; } @@ -87,13 +88,15 @@ public static function parse(Parser $parser, TokensList $list, array $options = } if ($state === 0) { - $ret->name = $token->value; - $state = 1; - } elseif ($state === 1) { - if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { - $ret->parameters = ArrayObj::parse($parser, $list); + if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') { + --$list->idx; // ArrayObj needs to start with `(` + $state = 1; + continue;// do not add this token to the name } + $ret->name .= $token->value; + } elseif ($state === 1) { + $ret->parameters = ArrayObj::parse($parser, $list); break; } } diff --git a/src/Statement.php b/src/Statement.php index c5ebd2dca..28de61255 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -4,7 +4,6 @@ namespace PhpMyAdmin\SqlParser; -use PhpMyAdmin\SqlParser\Components\FunctionCall; use PhpMyAdmin\SqlParser\Components\OptionsArray; use Stringable; @@ -415,13 +414,6 @@ public function parse(Parser $parser, TokensList $list) } $this->after($parser, $list, $token); - - // #223 Here may make a patch, if last is delimiter, back one - if ($class !== FunctionCall::class || $list->offsetGet($list->idx)->type !== Token::TYPE_DELIMITER) { - continue; - } - - --$list->idx; } // This may be corrected by the parser. diff --git a/tests/Builder/CallStatementTest.php b/tests/Builder/CallStatementTest.php index cfee72703..d5a7bceea 100644 --- a/tests/Builder/CallStatementTest.php +++ b/tests/Builder/CallStatementTest.php @@ -31,7 +31,7 @@ public function testBuilderShort(): void public function testBuilderWithDbName(): void { - $query = 'CALL foo()'; + $query = 'CALL mydb.foo()'; $parser = new Parser($query); $stmt = $parser->statements[0]; @@ -41,7 +41,7 @@ public function testBuilderWithDbName(): void public function testBuilderWithDbNameShort(): void { - $query = 'CALL foo'; + $query = 'CALL mydb.foo'; $parser = new Parser($query); $stmt = $parser->statements[0]; @@ -51,12 +51,12 @@ public function testBuilderWithDbNameShort(): void public function testBuilderWithDbNameAndParams(): void { - $query = 'CALL foo(@bar, @baz);'; + $query = 'CALL mydb.foo(@bar, @baz);'; $parser = new Parser($query); $stmt = $parser->statements[0]; - $this->assertEquals('CALL foo(@bar,@baz)', $stmt->build()); + $this->assertEquals('CALL mydb.foo(@bar,@baz)', $stmt->build()); } public function testBuilderMultiCallsShort(): void