From c4547fc66686d87285c6c495f2e7b0983b2660fa Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 1 Sep 2026 01:52:38 +0100 Subject: [PATCH] Refactor getVariablesStatus() Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 46 ++------------------------------------ psalm-baseline.xml | 40 ++++++--------------------------- src/Engines/Innodb.php | 2 +- src/Engines/Memory.php | 2 +- src/Engines/Myisam.php | 2 +- src/Engines/Ndbcluster.php | 2 +- src/Engines/Pbxt.php | 2 +- src/StorageEngine.php | 31 +++++++++++++------------ 8 files changed, 29 insertions(+), 98 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ccefd95bef..26f543eb6c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12771,12 +12771,6 @@ parameters: count: 1 path: src/StorageEngine.php - - - message: '#^Cannot access offset ''desc'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/StorageEngine.php - - message: '#^Cannot access offset ''disk_usage'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12789,22 +12783,10 @@ parameters: count: 1 path: src/StorageEngine.php - - - message: '#^Cannot access offset ''title'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: src/StorageEngine.php - - message: '#^Cannot access offset ''type'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 4 - path: src/StorageEngine.php - - - - message: '#^Cannot access offset ''value'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 4 + count: 1 path: src/StorageEngine.php - @@ -12832,31 +12814,7 @@ parameters: path: src/StorageEngine.php - - message: '#^Parameter \#1 \$haystack of function mb_stripos expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/StorageEngine.php - - - - message: '#^Parameter \#1 \$message of static method PhpMyAdmin\\Html\\Generator\:\:showHint\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/StorageEngine.php - - - - message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#' - identifier: argument.type - count: 2 - path: src/StorageEngine.php - - - - message: '#^Parameter \#1 \$value of method PhpMyAdmin\\StorageEngine\:\:resolveTypeSize\(\) expects int\|string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/StorageEngine.php - - - - message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatNumber\(\) expects float\|int\|numeric\-string, mixed given\.$#' + message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatNumber\(\) expects float\|int\|numeric\-string, string given\.$#' identifier: argument.type count: 1 path: src/StorageEngine.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 23ce0d4b22..d197f8abe9 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7552,6 +7552,9 @@ + + + @@ -7559,37 +7562,17 @@ - - - - - - - - - - - - - - - - - - - - @@ -7602,19 +7585,10 @@ - - - - - - - - - - - - - + + + + diff --git a/src/Engines/Innodb.php b/src/Engines/Innodb.php index 57ba703799..bd49e38ff6 100644 --- a/src/Engines/Innodb.php +++ b/src/Engines/Innodb.php @@ -21,7 +21,7 @@ class Innodb extends StorageEngine /** * Returns array with variable names related to InnoDB storage engine * - * @return mixed[] variable names + * @return array variable names */ public function getVariables(): array { diff --git a/src/Engines/Memory.php b/src/Engines/Memory.php index 464399ed61..f995c345d9 100644 --- a/src/Engines/Memory.php +++ b/src/Engines/Memory.php @@ -17,7 +17,7 @@ class Memory extends StorageEngine /** * Returns array with variable names dedicated to MEMORY storage engine * - * @return mixed[] variable names + * @return array variable names */ public function getVariables(): array { diff --git a/src/Engines/Myisam.php b/src/Engines/Myisam.php index 0433d8569c..6fe94626a4 100644 --- a/src/Engines/Myisam.php +++ b/src/Engines/Myisam.php @@ -19,7 +19,7 @@ class Myisam extends StorageEngine /** * Returns array with variable names dedicated to MyISAM storage engine * - * @return mixed[] variable names + * @return array variable names */ public function getVariables(): array { diff --git a/src/Engines/Ndbcluster.php b/src/Engines/Ndbcluster.php index 833edee167..ba75e19d99 100644 --- a/src/Engines/Ndbcluster.php +++ b/src/Engines/Ndbcluster.php @@ -17,7 +17,7 @@ class Ndbcluster extends StorageEngine /** * Returns array with variable names related to NDBCLUSTER storage engine * - * @return mixed[] variable names + * @return array variable names */ public function getVariables(): array { diff --git a/src/Engines/Pbxt.php b/src/Engines/Pbxt.php index 7b0686fbf0..2e97d76b6e 100644 --- a/src/Engines/Pbxt.php +++ b/src/Engines/Pbxt.php @@ -24,7 +24,7 @@ class Pbxt extends StorageEngine /** * Returns array with variable names dedicated to PBXT storage engine * - * @return mixed[] variable names + * @return array variable names */ public function getVariables(): array { diff --git a/src/StorageEngine.php b/src/StorageEngine.php index 1094fece97..2932d2718d 100644 --- a/src/StorageEngine.php +++ b/src/StorageEngine.php @@ -340,7 +340,7 @@ class StorageEngine /** * Returns array with detailed info about engine specific server variables * - * @return mixed[] array with detailed info about specific engine server variables + * @return array */ public function getVariablesStatus(): array { @@ -355,24 +355,23 @@ class StorageEngine $sqlQuery = 'SHOW GLOBAL VARIABLES ' . $like . ';'; $res = DatabaseInterface::getInstance()->query($sqlQuery); - foreach ($res as $row) { - if (isset($variables[$row['Variable_name']])) { - $mysqlVars[$row['Variable_name']] = $variables[$row['Variable_name']]; - } elseif ($like === '' && mb_stripos($row['Variable_name'], $this->engine) !== 0) { + /** + * @var string $variableName + * @var string $value + */ + foreach ($res as ['Variable_name' => $variableName, 'Value' => $value]) { + if (! isset($variables[$variableName]) && $like === '' && mb_stripos($variableName, $this->engine) !== 0) { continue; } - $mysqlVars[$row['Variable_name']]['value'] = $row['Value']; + $variableInfo = $variables[$variableName] ?? []; - if (empty($mysqlVars[$row['Variable_name']]['title'])) { - $mysqlVars[$row['Variable_name']]['title'] = $row['Variable_name']; - } - - if (isset($mysqlVars[$row['Variable_name']]['type'])) { - continue; - } - - $mysqlVars[$row['Variable_name']]['type'] = self::DETAILS_TYPE_PLAINTEXT; + $mysqlVars[$variableName] = [ + 'title' => empty($variableInfo['title']) ? $variableName : $variableInfo['title'], + 'desc' => $variableInfo['desc'] ?? null, + 'type' => $variableInfo['type'] ?? self::DETAILS_TYPE_PLAINTEXT, + 'value' => $value, + ]; } return $mysqlVars; @@ -420,7 +419,7 @@ class StorageEngine * engine. This function should be overridden when extending this class * for a particular engine. * - * @return mixed[] The list of variables. + * @return array The list of variables. */ public function getVariables(): array {