Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1230,12 +1230,6 @@ parameters:
count: 1
path: src/Statements/ExplainStatement.php

-
message: '#^Cannot access property \$value on PhpMyAdmin\\SqlParser\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Statements/ExplainStatement.php

-
message: '#^Class PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement has an uninitialized property \$statementAlias\. Give it default value or assign it in the constructor\.$#'
identifier: property.uninitialized
Expand All @@ -1260,12 +1254,6 @@ parameters:
count: 1
path: src/Statements/ExplainStatement.php

-
message: '#^Property PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement\:\:\$connectionId \(int\|null\) does not accept bool\|float\|int\|string\.$#'
identifier: assign.propertyType
count: 1
path: src/Statements/ExplainStatement.php

-
message: '#^Property PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement\:\:\$explainedDatabase \(string\|null\) does not accept bool\|float\|int\|string\.$#'
identifier: assign.propertyType
Expand Down
2 changes: 0 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,11 @@
<file src="src/Statements/ExplainStatement.php">
<PossiblyNullPropertyFetch>
<code><![CDATA[$nextToken->keyword]]></code>
<code><![CDATA[$nextToken->value]]></code>
</PossiblyNullPropertyFetch>
<PropertyNotSetInConstructor>
<code><![CDATA[$statementAlias]]></code>
</PropertyNotSetInConstructor>
<PropertyTypeCoercion>
<code><![CDATA[$nextToken->value]]></code>
<code><![CDATA[$token->value]]></code>
<code><![CDATA[$token->value]]></code>
</PropertyTypeCoercion>
Expand Down
6 changes: 6 additions & 0 deletions src/Statements/ExplainStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpMyAdmin\SqlParser\TokenType;

use function array_slice;
use function is_int;

/**
* `EXPLAIN` statement.
Expand Down Expand Up @@ -95,7 +96,7 @@
*/
$miniState = 0;

for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 99 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ */ $miniState = 0; - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { /** * Token parsed at this moment. */
/**
* Token parsed at this moment.
*/
Expand All @@ -117,7 +118,7 @@
$state = 1;
$this->statementAlias = 'ANALYZE';
} elseif (
$token->keyword === 'EXPLAIN'

Check warning on line 121 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOrAllSubExprNegation": @@ @@ $state = 1; $this->statementAlias = 'ANALYZE'; } elseif ( - $token->keyword === 'EXPLAIN' - || $token->keyword === 'DESC' - || $token->keyword === 'DESCRIBE' + !($token->keyword === 'EXPLAIN') || !($token->keyword === 'DESC') || !($token->keyword === 'DESCRIBE') ) { $this->statementAlias = $token->keyword;
|| $token->keyword === 'DESC'
|| $token->keyword === 'DESCRIBE'
) {
Expand All @@ -134,12 +135,12 @@
continue;
}

$miniState = 1;

Check warning on line 138 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "IncrementInteger": @@ @@ continue; } - $miniState = 1; + $miniState = 2; $lastIdx = $list->idx; $nextKeyword = $list->getNextOfTypeAndValue(TokenType::Keyword, 'ANALYZE');

$lastIdx = $list->idx;
$nextKeyword = $list->getNextOfTypeAndValue(TokenType::Keyword, 'ANALYZE');
if ($nextKeyword && $nextKeyword->keyword !== null) {
$miniState = 2;

Check warning on line 143 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "IncrementInteger": @@ @@ $lastIdx = $list->idx; $nextKeyword = $list->getNextOfTypeAndValue(TokenType::Keyword, 'ANALYZE'); if ($nextKeyword && $nextKeyword->keyword !== null) { - $miniState = 2; + $miniState = 3; $this->statementAlias .= ' ANALYZE'; } else { $list->idx = $lastIdx;

Check warning on line 143 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "DecrementInteger": @@ @@ $lastIdx = $list->idx; $nextKeyword = $list->getNextOfTypeAndValue(TokenType::Keyword, 'ANALYZE'); if ($nextKeyword && $nextKeyword->keyword !== null) { - $miniState = 2; + $miniState = 1; $this->statementAlias .= ' ANALYZE'; } else { $list->idx = $lastIdx;
$this->statementAlias .= ' ANALYZE';
} else {
$list->idx = $lastIdx;
Expand All @@ -161,6 +162,11 @@
$list->idx++; // Ignore the current token
$list->getNext(); // CONNECTION
$nextToken = $list->getNext(); // Identifier
if ($nextToken === null || $nextToken->type !== TokenType::Number || ! is_int($nextToken->value)) {

Check warning on line 165 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOr": @@ @@ $list->idx++; // Ignore the current token $list->getNext(); // CONNECTION $nextToken = $list->getNext(); // Identifier - if ($nextToken === null || $nextToken->type !== TokenType::Number || ! is_int($nextToken->value)) { + if ($nextToken === null && $nextToken->type !== TokenType::Number || ! is_int($nextToken->value)) { $parser->error('Unexpected token.', $nextToken); break; }
$parser->error('Unexpected token.', $nextToken);
break;
}

$this->connectionId = $nextToken->value;
break;
}
Expand Down Expand Up @@ -194,7 +200,7 @@
$list->idx = $idxOfLastParsedToken;
break;
} elseif ($state === 3) {
if (($token->type === TokenType::Operator) && ($token->value === '.')) {

Check warning on line 203 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAnd": @@ @@ $list->idx = $idxOfLastParsedToken; break; } elseif ($state === 3) { - if (($token->type === TokenType::Operator) && ($token->value === '.')) { + if ($token->type === TokenType::Operator || $token->value === '.') { continue; }
continue;
}

Expand All @@ -213,7 +219,7 @@
continue;
}

if ($this->explainedColumn === null && $token->value !== null) {

Check warning on line 222 in src/Statements/ExplainStatement.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAnd": @@ @@ continue; } - if ($this->explainedColumn === null && $token->value !== null) { + if ($this->explainedColumn === null || $token->value !== null) { $this->explainedColumn = (string) $token->value; } }
$this->explainedColumn = (string) $token->value;
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Parser/ExplainStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ public static function explainProvider(): array
['parser/parseExplain12'],
['parser/parseExplain13'],
['parser/parseExplain14'],
['parser/parseExplain15'],
['parser/parseExplainErr'],
['parser/parseExplainErr1'],
['parser/parseExplainErr2'],
['parser/parseExplainErr3'],
['parser/parseExplainErr4'],
['parser/parseExplainErr5'],
['parser/parseExplainErr6'],
];
}
}
1 change: 1 addition & 0 deletions tests/data/parser/parseExplain15.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPLAIN FOR CONNECTION 458
146 changes: 146 additions & 0 deletions tests/data/parser/parseExplain15.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"query": "EXPLAIN FOR CONNECTION 458",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"strict": false,
"errors": [],
"str": "EXPLAIN FOR CONNECTION 458",
"len": 26,
"last": 26,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"count": 8,
"idx": 8,
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "EXPLAIN",
"value": "EXPLAIN",
"keyword": "EXPLAIN",
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Keyword",
"value": 1
},
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Whitespace",
"value": 3
},
"flags": 0,
"position": 7
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "FOR",
"value": "FOR",
"keyword": "FOR",
"type": {
"@type": "@3"
},
"flags": 3,
"position": 8
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "CONNECTION",
"value": "CONNECTION",
"keyword": "CONNECTION",
"type": {
"@type": "@3"
},
"flags": 1,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 22
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "458",
"value": 458,
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Number",
"value": 6
},
"flags": 0,
"position": 23
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "",
"value": "",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Delimiter",
"value": 9
},
"flags": 0,
"position": null
}
]
},
"delimiter": ";",
"delimiterLen": 1
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"strict": false,
"errors": [],
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement",
"bodyParser": null,
"statementAlias": "EXPLAIN",
"connectionId": 458,
"explainedDatabase": null,
"explainedTable": null,
"explainedColumn": null,
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": []
},
"first": 0,
"last": 7
}
],
"brackets": 0
},
"errors": {
"lexer": [],
"parser": []
}
}
1 change: 1 addition & 0 deletions tests/data/parser/parseExplainErr4.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPLAIN FOR CONNECTION
130 changes: 130 additions & 0 deletions tests/data/parser/parseExplainErr4.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"query": "EXPLAIN FOR CONNECTION",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"strict": false,
"errors": [],
"str": "EXPLAIN FOR CONNECTION",
"len": 22,
"last": 22,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"count": 6,
"idx": 7,
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "EXPLAIN",
"value": "EXPLAIN",
"keyword": "EXPLAIN",
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Keyword",
"value": 1
},
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Whitespace",
"value": 3
},
"flags": 0,
"position": 7
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "FOR",
"value": "FOR",
"keyword": "FOR",
"type": {
"@type": "@3"
},
"flags": 3,
"position": 8
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "CONNECTION",
"value": "CONNECTION",
"keyword": "CONNECTION",
"type": {
"@type": "@3"
},
"flags": 1,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "",
"value": "",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Delimiter",
"value": 9
},
"flags": 0,
"position": null
}
]
},
"delimiter": ";",
"delimiterLen": 1
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"strict": false,
"errors": [],
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement",
"bodyParser": null,
"statementAlias": "EXPLAIN",
"connectionId": null,
"explainedDatabase": null,
"explainedTable": null,
"explainedColumn": null,
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": []
},
"first": 0,
"last": 6
}
],
"brackets": 0
},
"errors": {
"lexer": [],
"parser": [
[
"Unexpected token.",
{
"@type": "@9"
},
0
]
]
}
}
1 change: 1 addition & 0 deletions tests/data/parser/parseExplainErr5.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPLAIN FOR CONNECTION abc
Loading
Loading