From bfb5838b4edbb5cac7105f8c0327594490c49cf8 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 15:02:54 +0000 Subject: [PATCH] Remove $GLOBALS['query'] Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 34 ++----------------- psalm-baseline.xml | 13 ------- .../Preferences/ManageController.php | 5 ++- src/Controllers/Table/ReplaceController.php | 13 ++++--- src/Core.php | 2 +- src/InsertEdit.php | 2 +- 6 files changed, 12 insertions(+), 57 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a98fdba9b4..cae9dfcb54 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4596,7 +4596,7 @@ parameters: - message: '#^Cannot access an offset on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 2 + count: 1 path: src/Controllers/Table/ReplaceController.php - @@ -4626,7 +4626,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 8 + count: 7 path: src/Controllers/Table/ReplaceController.php - @@ -4683,18 +4683,6 @@ parameters: count: 1 path: src/Controllers/Table/ReplaceController.php - - - message: '#^Parameter \#1 \$query of method PhpMyAdmin\\InsertEdit\:\:executeSqlQuery\(\) expects array\, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/ReplaceController.php - - - - message: '#^Parameter \#1 \$queryData of static method PhpMyAdmin\\Core\:\:previewSQL\(\) expects array\\|string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/ReplaceController.php - - message: '#^Parameter \#2 \$relationField of method PhpMyAdmin\\InsertEdit\:\:getLinkForRelationalDisplayField\(\) expects string, \(int\|string\) given\.$#' identifier: argument.type @@ -5613,12 +5601,6 @@ parameters: count: 1 path: src/Core.php - - - message: '#^Parameter \#1 \$sqlQuery of static method PhpMyAdmin\\Html\\Generator\:\:formatSql\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Core.php - - message: '#^Parameter \#1 \$value of function count expects array\|Countable, mixed given\.$#' identifier: argument.type @@ -9768,18 +9750,6 @@ parameters: count: 1 path: src/InsertEdit.php - - - message: '#^Parameter \#1 \$query of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:query\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/InsertEdit.php - - - - message: '#^Parameter \#1 \$query of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:tryQuery\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/InsertEdit.php - - message: '#^Parameter \#1 \$sqlQuery of static method PhpMyAdmin\\Core\:\:checkSqlQuerySignature\(\) expects string, mixed given\.$#' identifier: argument.type diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7ce1f1f1f5..7e2cf91535 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1890,9 +1890,6 @@ - - - @@ -1901,7 +1898,6 @@ - @@ -2932,7 +2928,6 @@ - @@ -2975,7 +2970,6 @@ - @@ -3016,7 +3010,6 @@ - @@ -3522,7 +3515,6 @@ - @@ -3541,7 +3533,6 @@ - @@ -5756,12 +5747,9 @@ - - - @@ -5789,7 +5777,6 @@ - diff --git a/src/Controllers/Preferences/ManageController.php b/src/Controllers/Preferences/ManageController.php index 5dfce85b2c..bc25b7e640 100644 --- a/src/Controllers/Preferences/ManageController.php +++ b/src/Controllers/Preferences/ManageController.php @@ -60,7 +60,6 @@ final class ManageController implements InvocableController public function __invoke(ServerRequest $request): Response { $GLOBALS['error'] ??= null; - $GLOBALS['query'] ??= null; $route = $request->getRoute(); @@ -202,10 +201,10 @@ final class ManageController implements InvocableController $result = $this->userPreferences->save($configFile->getConfigArray()); if ($result === true) { if ($returnUrl !== null && $returnUrl !== '') { - $GLOBALS['query'] = Util::splitURLQuery($returnUrl); + $query = Util::splitURLQuery($returnUrl); $returnUrl = parse_url($returnUrl, PHP_URL_PATH); - foreach ($GLOBALS['query'] as $q) { + foreach ($query as $q) { $pos = mb_strpos($q, '='); $k = mb_substr($q, 0, (int) $pos); if ($k === 'token') { diff --git a/src/Controllers/Table/ReplaceController.php b/src/Controllers/Table/ReplaceController.php index f65f18e219..7b74422304 100644 --- a/src/Controllers/Table/ReplaceController.php +++ b/src/Controllers/Table/ReplaceController.php @@ -73,7 +73,6 @@ final class ReplaceController implements InvocableController $GLOBALS['unsaved_values'] ??= null; $GLOBALS['disp_query'] ??= null; $GLOBALS['disp_message'] ??= null; - $GLOBALS['query'] ??= null; $this->dbi->selectDb(Current::$database); @@ -103,7 +102,7 @@ final class ReplaceController implements InvocableController $isInsertignore = $request->getParsedBodyParam('submit_type') === 'insertignore'; - $GLOBALS['query'] = []; + $query = []; $valueSets = []; $mimeMap = $this->transformations->getMime(Current::$database, Current::$table) ?? []; @@ -255,7 +254,7 @@ final class ReplaceController implements InvocableController } else { // build update query $clauseIsUnique = $request->getParam('clause_is_unique', '');// Should contain 0 or 1 - $GLOBALS['query'][] = 'UPDATE ' . Util::backquote(Current::$table) + $query[] = 'UPDATE ' . Util::backquote(Current::$table) . ' SET ' . implode(', ', $queryValues) . ' WHERE ' . $whereClause . ($clauseIsUnique ? '' : ' LIMIT 1'); @@ -279,13 +278,13 @@ final class ReplaceController implements InvocableController // Builds the sql query if ($isInsert && $valueSets !== []) { - $GLOBALS['query'] = (array) QueryGenerator::buildInsertSqlQuery( + $query = (array) QueryGenerator::buildInsertSqlQuery( Current::$table, $isInsertignore, $queryFields, $valueSets, ); - } elseif (empty($GLOBALS['query']) && ! $request->hasBodyParam('preview_sql') && ! $rowSkipped) { + } elseif ($query === [] && ! $request->hasBodyParam('preview_sql') && ! $rowSkipped) { // No change -> move back to the calling script // // Note: logic passes here for inline edit @@ -300,7 +299,7 @@ final class ReplaceController implements InvocableController // If there is a request for SQL previewing. if ($request->hasBodyParam('preview_sql')) { - Core::previewSQL($GLOBALS['query']); + Core::previewSQL($query); return $this->response->response(); } @@ -320,7 +319,7 @@ final class ReplaceController implements InvocableController $lastMessages, $warningMessages, $errorMessages, - ] = $this->insertEdit->executeSqlQuery($GLOBALS['query']); + ] = $this->insertEdit->executeSqlQuery($query); if ($isInsert && ($valueSets !== [] || $rowSkipped)) { Current::$message = Message::getMessageForInsertedRows($totalAffectedRows); diff --git a/src/Core.php b/src/Core.php index 0726c3e54b..ce15a320e5 100644 --- a/src/Core.php +++ b/src/Core.php @@ -490,7 +490,7 @@ class Core /** * Displays SQL query before executing. * - * @param mixed[]|string $queryData Array containing queries or query itself + * @param string[]|string $queryData Array containing queries or query itself */ public static function previewSQL(array|string $queryData): void { diff --git a/src/InsertEdit.php b/src/InsertEdit.php index 03411da3c2..2824555311 100644 --- a/src/InsertEdit.php +++ b/src/InsertEdit.php @@ -903,7 +903,7 @@ class InsertEdit /** * Executes the sql query and get the result, then move back to the calling page * - * @param mixed[] $query built query from buildSqlQuery() + * @param string[] $query built query from buildSqlQuery() * * @return array{int, Message[], string[], string[]} */