From 6aa4bc2e5008dd299a6db8cf0ea0bbeab4da8643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 5 Feb 2024 17:18:58 -0300 Subject: [PATCH] Update sql-parser dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a quick fix for the sql-parser update. Signed-off-by: MaurĂ­cio Meneghini Fauth --- composer.lock | 8 ++-- phpstan-baseline.neon | 55 --------------------------- psalm-baseline.xml | 16 -------- src/ParseAnalyze.php | 22 +++++------ src/Sql.php | 2 +- src/StatementInfo.php | 39 +++++++++++++++++++ tests/classes/Display/ResultsTest.php | 6 +-- 7 files changed, 56 insertions(+), 92 deletions(-) diff --git a/composer.lock b/composer.lock index 6c78e41da4..72bd991136 100644 --- a/composer.lock +++ b/composer.lock @@ -454,12 +454,12 @@ "source": { "type": "git", "url": "https://github.com/phpmyadmin/sql-parser.git", - "reference": "0e24506244a1f4dde047af1eb71a32c8cb5a6e75" + "reference": "c4efadf4562ad049a7244b90664c03cd568c3ebc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/0e24506244a1f4dde047af1eb71a32c8cb5a6e75", - "reference": "0e24506244a1f4dde047af1eb71a32c8cb5a6e75", + "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/c4efadf4562ad049a7244b90664c03cd568c3ebc", + "reference": "c4efadf4562ad049a7244b90664c03cd568c3ebc", "shasum": "" }, "require": { @@ -538,7 +538,7 @@ "type": "other" } ], - "time": "2024-02-01T15:02:04+00:00" + "time": "2024-02-05T17:02:03+00:00" }, { "name": "phpmyadmin/twig-i18n-extension", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4b18099c53..fa18d0356f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10205,51 +10205,6 @@ parameters: count: 2 path: src/Operations.php - - - message: "#^Cannot access offset 0 on mixed\\.$#" - count: 3 - path: src/ParseAnalyze.php - - - - message: "#^Cannot access offset 1 on mixed\\.$#" - count: 1 - path: src/ParseAnalyze.php - - - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 2 - path: src/ParseAnalyze.php - - - - message: "#^Offset 'select_tables' does not exist on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\}\\.$#" - count: 1 - path: src/ParseAnalyze.php - - - - message: "#^Offset 'select_tables' on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} in empty\\(\\) does not exist\\.$#" - count: 1 - path: src/ParseAnalyze.php - - - - message: "#^Offset 'select_tables' on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} in isset\\(\\) does not exist\\.$#" - count: 1 - path: src/ParseAnalyze.php - - - - message: "#^Offset 'select_tables' on array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} on left side of \\?\\? does not exist\\.$#" - count: 1 - path: src/ParseAnalyze.php - - - - message: "#^Parameter \\#1 \\$info of static method PhpMyAdmin\\\\StatementInfo\\:\\:fromArray\\(\\) expects array\\{distinct\\: bool, drop_database\\: bool, group\\: bool, having\\: bool, is_affected\\: bool, is_analyse\\: bool, is_count\\: bool, is_delete\\: bool, \\.\\.\\.\\}, array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} given\\.$#" - count: 1 - path: src/ParseAnalyze.php - - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#" - count: 1 - path: src/ParseAnalyze.php - - message: "#^Cannot access offset 'Table' on mixed\\.$#" count: 4 @@ -14415,11 +14370,6 @@ parameters: count: 1 path: src/Sql.php - - - message: "#^Parameter \\#1 \\$info of static method PhpMyAdmin\\\\StatementInfo\\:\\:fromArray\\(\\) expects array\\{distinct\\: bool, drop_database\\: bool, group\\: bool, having\\: bool, is_affected\\: bool, is_analyse\\: bool, is_count\\: bool, is_delete\\: bool, \\.\\.\\.\\}, array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} given\\.$#" - count: 1 - path: src/Sql.php - - message: "#^Parameter \\#1 \\$rows of static method PhpMyAdmin\\\\Message\\:\\:getMessageForAffectedRows\\(\\) expects int, int\\|string given\\.$#" count: 2 @@ -16465,11 +16415,6 @@ parameters: count: 2 path: tests/classes/Display/ResultsTest.php - - - message: "#^Parameter \\#1 \\$info of static method PhpMyAdmin\\\\StatementInfo\\:\\:fromArray\\(\\) expects array\\{distinct\\: bool, drop_database\\: bool, group\\: bool, having\\: bool, is_affected\\: bool, is_analyse\\: bool, is_count\\: bool, is_delete\\: bool, \\.\\.\\.\\}, array\\{distinct\\?\\: bool, drop_database\\?\\: bool, group\\?\\: bool, having\\?\\: bool, is_affected\\?\\: bool, is_analyse\\?\\: bool, is_count\\?\\: bool, is_delete\\?\\: bool, \\.\\.\\.\\} given\\.$#" - count: 3 - path: tests/classes/Display/ResultsTest.php - - message: "#^Parameter \\#1 \\$string of function htmlspecialchars_decode expects string, mixed given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7610ddfaef..e3bd080f6d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7850,14 +7850,6 @@ - - - $info - - - - - @@ -11504,9 +11496,6 @@ - - Query::getAll($fullSqlQuery) - Config::getInstance() Config::getInstance() @@ -14165,11 +14154,6 @@ - - Query::getAll($query) - Query::getAll($query) - - Config::getInstance() Config::getInstance() diff --git a/src/ParseAnalyze.php b/src/ParseAnalyze.php index 083ceae893..1d407ad2dc 100644 --- a/src/ParseAnalyze.php +++ b/src/ParseAnalyze.php @@ -1,7 +1,4 @@ selectTables !== []) { // Previous table and database name is stored to check if it changed. $previousDb = $db; - if (count($info['select_tables']) > 1) { - + if (count($info->selectTables) > 1) { /** * @todo if there are more than one table name in the Select: * - do not extract the first table name @@ -52,21 +48,21 @@ class ParseAnalyze */ $table = ''; } else { - $table = $info['select_tables'][0][0] ?? ''; - if (isset($info['select_tables'][0][1])) { - $db = $info['select_tables'][0][1]; + $table = $info->selectTables[0][0] ?? ''; + if (isset($info->selectTables[0][1])) { + $db = $info->selectTables[0][1]; } } // There is no point checking if a reloading is required if we already decided // to reload. Also, no reload is required for AJAX requests. $response = ResponseRenderer::getInstance(); - if (empty($info['reload']) && ! $response->isAjax()) { + if (! $info->flags->reload && ! $response->isAjax()) { // NOTE: Database names are case-insensitive. - $info['reload'] = strcasecmp($db, $previousDb) !== 0; + $info->flags->reload = strcasecmp($db, $previousDb) !== 0; } } - return [StatementInfo::fromArray($info), $db, $table]; + return [StatementInfo::fromStatementInfo($info), $db, $table]; } } diff --git a/src/Sql.php b/src/Sql.php index 3b0212e682..ee8bcd0fff 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -100,7 +100,7 @@ class Sql ); // TODO: Avoid reparsing the query. - $statementInfo = StatementInfo::fromArray(Query::getAll($fullSqlQuery)); + $statementInfo = StatementInfo::fromStatementInfo(Query::getAll($fullSqlQuery)); } else { // Store the remembered table into session. $tableObject->setUiProp( diff --git a/src/StatementInfo.php b/src/StatementInfo.php index cc23be1cc9..0ce02cd6fa 100644 --- a/src/StatementInfo.php +++ b/src/StatementInfo.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statement; +use PhpMyAdmin\SqlParser\Utils\StatementInfo as SqlParserStatementInfo; /** @psalm-immutable */ class StatementInfo @@ -126,4 +127,42 @@ class StatementInfo $info['select_expr'] ?? [], ); } + + public static function fromStatementInfo(SqlParserStatementInfo $statementInfo): self + { + /** @psalm-suppress DeprecatedProperty */ + return new self( + $statementInfo->flags->distinct, + $statementInfo->flags->dropDatabase, + $statementInfo->flags->group, + $statementInfo->flags->having, + $statementInfo->flags->isAffected, + $statementInfo->flags->isAnalyse, + $statementInfo->flags->isCount, + $statementInfo->flags->isDelete, + $statementInfo->flags->isExplain, + $statementInfo->flags->isExport, + $statementInfo->flags->isFunc, + $statementInfo->flags->isGroup, + $statementInfo->flags->isInsert, + $statementInfo->flags->isMaint, + $statementInfo->flags->isProcedure, + $statementInfo->flags->isReplace, + $statementInfo->flags->isSelect, + $statementInfo->flags->isShow, + $statementInfo->flags->isSubQuery, + $statementInfo->flags->join, + $statementInfo->flags->limit, + $statementInfo->flags->offset, + $statementInfo->flags->order, + $statementInfo->flags->queryType?->value ?? false, + $statementInfo->flags->reload, + $statementInfo->flags->selectFrom, + $statementInfo->flags->union, + $statementInfo->parser, + $statementInfo->statement, + $statementInfo->selectTables, + $statementInfo->selectExpressions, + ); + } } diff --git a/tests/classes/Display/ResultsTest.php b/tests/classes/Display/ResultsTest.php index 852ffe4289..f61c64519b 100644 --- a/tests/classes/Display/ResultsTest.php +++ b/tests/classes/Display/ResultsTest.php @@ -101,7 +101,7 @@ class ResultsTest extends AbstractTestCase $this->object, DisplayResults::class, 'isSelect', - [StatementInfo::fromArray(Query::getAll('SELECT * FROM pma'))], + [StatementInfo::fromStatementInfo(Query::getAll('SELECT * FROM pma'))], ), ); } @@ -321,7 +321,7 @@ class ResultsTest extends AbstractTestCase $this->object, DisplayResults::class, 'setHighlightedColumnGlobalField', - [StatementInfo::fromArray(Query::getAll($query))], + [StatementInfo::fromStatementInfo(Query::getAll($query))], ); self::assertEquals([ @@ -712,7 +712,7 @@ class ResultsTest extends AbstractTestCase 'disabled', false, $query, - StatementInfo::fromArray(Query::getAll($query)), + StatementInfo::fromStatementInfo(Query::getAll($query)), ], );