Skip to content

Commit d28f1ea

Browse files
Merge pull request #546 from MauricioFauth/select-stmt
Push Statement::parse() down to SelectStatement
2 parents de2d27f + 7f61f31 commit d28f1ea

File tree

3 files changed

+327
-48
lines changed

3 files changed

+327
-48
lines changed

phpstan-baseline.neon

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,121 @@ parameters:
595595
count: 1
596596
path: src/Statements/RenameStatement.php
597597

598+
-
599+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$call\\.$#"
600+
count: 1
601+
path: src/Statements/SelectStatement.php
602+
603+
-
604+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$fields\\.$#"
605+
count: 1
606+
path: src/Statements/SelectStatement.php
607+
608+
-
609+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$renames\\.$#"
610+
count: 1
611+
path: src/Statements/SelectStatement.php
612+
613+
-
614+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$set\\.$#"
615+
count: 1
616+
path: src/Statements/SelectStatement.php
617+
618+
-
619+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$table\\.$#"
620+
count: 1
621+
path: src/Statements/SelectStatement.php
622+
623+
-
624+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$tables\\.$#"
625+
count: 1
626+
path: src/Statements/SelectStatement.php
627+
628+
-
629+
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$values\\.$#"
630+
count: 1
631+
path: src/Statements/SelectStatement.php
632+
633+
-
634+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$options \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
635+
count: 1
636+
path: src/Statements/SelectStatement.php
637+
638+
-
639+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$endOptions \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
640+
count: 1
641+
path: src/Statements/SelectStatement.php
642+
643+
-
644+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$expr \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\>\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
645+
count: 1
646+
path: src/Statements/SelectStatement.php
647+
648+
-
649+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$from \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\>\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
650+
count: 1
651+
path: src/Statements/SelectStatement.php
652+
653+
-
654+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$group \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\GroupKeyword\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
655+
count: 1
656+
path: src/Statements/SelectStatement.php
657+
658+
-
659+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$groupOptions \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
660+
count: 1
661+
path: src/Statements/SelectStatement.php
662+
663+
-
664+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$having \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
665+
count: 1
666+
path: src/Statements/SelectStatement.php
667+
668+
-
669+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$indexHints \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\IndexHint\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
670+
count: 1
671+
path: src/Statements/SelectStatement.php
672+
673+
-
674+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$into \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
675+
count: 1
676+
path: src/Statements/SelectStatement.php
677+
678+
-
679+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$join \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\JoinKeyword\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
680+
count: 1
681+
path: src/Statements/SelectStatement.php
682+
683+
-
684+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$limit \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
685+
count: 1
686+
path: src/Statements/SelectStatement.php
687+
688+
-
689+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$order \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\OrderKeyword\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
690+
count: 1
691+
path: src/Statements/SelectStatement.php
692+
693+
-
694+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$partition \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
695+
count: 1
696+
path: src/Statements/SelectStatement.php
697+
698+
-
699+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$procedure \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
700+
count: 1
701+
path: src/Statements/SelectStatement.php
702+
703+
-
704+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$union \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\>\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
705+
count: 1
706+
path: src/Statements/SelectStatement.php
707+
708+
-
709+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$where \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
710+
count: 1
711+
path: src/Statements/SelectStatement.php
712+
598713
-
599714
message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
600715
count: 1

src/Statement.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -226,32 +226,6 @@ public function parse(Parser $parser, TokensList $list): void
226226
break;
227227
}
228228

229-
$lastIdx = $list->idx;
230-
231-
// ON DUPLICATE KEY UPDATE ...
232-
// has to be parsed in parent statement (INSERT or REPLACE)
233-
// so look for it and break
234-
if ($this instanceof SelectStatement && $token->value === 'ON') {
235-
++$list->idx; // Skip ON
236-
237-
// look for ON DUPLICATE KEY UPDATE
238-
$first = $list->getNextOfType(TokenType::Keyword);
239-
$second = $list->getNextOfType(TokenType::Keyword);
240-
$third = $list->getNextOfType(TokenType::Keyword);
241-
242-
if (
243-
$first && $second && $third
244-
&& $first->value === 'DUPLICATE'
245-
&& $second->value === 'KEY'
246-
&& $third->value === 'UPDATE'
247-
) {
248-
$list->idx = $lastIdx;
249-
break;
250-
}
251-
}
252-
253-
$list->idx = $lastIdx;
254-
255229
/**
256230
* The name of the class that is used for parsing.
257231
*/
@@ -327,33 +301,15 @@ public function parse(Parser $parser, TokensList $list): void
327301
$parsedOptions = true;
328302
}
329303
} elseif ($class === null) {
330-
if ($this instanceof SelectStatement && $token->value === 'WITH ROLLUP') {
331-
// Handle group options in Select statement
332-
$this->groupOptions = OptionsArrays::parse(
333-
$parser,
334-
$list,
335-
SelectStatement::STATEMENT_GROUP_OPTIONS,
336-
);
337-
} elseif (
338-
$this instanceof SelectStatement
339-
&& ($token->value === 'FOR UPDATE'
340-
|| $token->value === 'LOCK IN SHARE MODE')
341-
) {
342-
// Handle special end options in Select statement
343-
$this->endOptions = OptionsArrays::parse($parser, $list, SelectStatement::STATEMENT_END_OPTIONS);
344-
} elseif (
345-
$this instanceof SetStatement
346-
&& ($token->value === 'COLLATE'
347-
|| $token->value === 'DEFAULT')
348-
) {
349-
// Handle special end options in SET statement
350-
$this->endOptions = OptionsArrays::parse($parser, $list, SetStatement::STATEMENT_END_OPTIONS);
351-
} else {
304+
if (! ($this instanceof SetStatement) || ($token->value !== 'COLLATE' && $token->value !== 'DEFAULT')) {
352305
// There is no parser for this keyword and isn't the beginning
353306
// of a statement (so no options) either.
354307
$parser->error('Unrecognized keyword.', $token);
355308
continue;
356309
}
310+
311+
// Handle special end options in SET statement
312+
$this->endOptions = OptionsArrays::parse($parser, $list, SetStatement::STATEMENT_END_OPTIONS);
357313
}
358314

359315
$this->before($parser, $list, $token);

0 commit comments

Comments
 (0)