From 398d99b6211e6ca2f37a783a74e1055b6e22add6 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 1 Sep 2026 00:53:17 +0100 Subject: [PATCH 1/4] Drop getErrorUrl() Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 6 ------ psalm-baseline.xml | 2 -- src/InsertEdit.php | 12 ------------ tests/unit/InsertEditTest.php | 17 ----------------- 4 files changed, 37 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index bb17fc7f21..d951ab3240 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -7383,12 +7383,6 @@ parameters: count: 1 path: src/InsertEdit.php - - - message: '#^Method PhpMyAdmin\\InsertEdit\:\:getErrorUrl\(\) should return string but returns mixed\.$#' - identifier: return.type - count: 1 - path: src/InsertEdit.php - - message: '#^Method PhpMyAdmin\\InsertEdit\:\:getFormParametersForInsertForm\(\) should return array\ but returns array\\.$#' identifier: return.type diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 62da751eb2..c4f3514b8c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4787,12 +4787,10 @@ - ]]> - insertEdit->getErrorUrl([]), - ); - - $_POST['err_url'] = 'localhost'; - self::assertSame( - 'localhost', - $this->insertEdit->getErrorUrl([]), - ); - } - /** * Test for executeSqlQuery */ From fed9933d600d0e083872f10f7f848a2c9298e393 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 1 Sep 2026 01:02:49 +0100 Subject: [PATCH 2/4] Drop $charLists param from getStringWidth() Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 24 -------- psalm-baseline.xml | 25 -------- src/Font.php | 131 ++++++++++++++++++---------------------- tests/unit/FontTest.php | 59 ------------------ 4 files changed, 58 insertions(+), 181 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d951ab3240..7c355b299e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5802,30 +5802,6 @@ parameters: count: 1 path: src/FlashMessenger.php - - - message: '#^Binary operation "\*" between int and mixed results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/Font.php - - - - message: '#^Cannot access offset ''chars'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Font.php - - - - message: '#^Cannot access offset ''modifier'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Font.php - - - - message: '#^Parameter \#1 \$search of function str_replace expects array\\|string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Font.php - - message: ''' #^Access to deprecated static property \$route of class PhpMyAdmin\\Routing\\Routing\: diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c4f3514b8c..116dfd814a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4034,31 +4034,6 @@ storage[self::STORAGE_KEY]]]> - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Font.php b/src/Font.php index 51be36aecc..9c69dc12ae 100644 --- a/src/Font.php +++ b/src/Font.php @@ -8,7 +8,6 @@ declare(strict_types=1); namespace PhpMyAdmin; use function ceil; -use function is_array; use function mb_strlen; use function mb_strtolower; use function preg_replace; @@ -19,69 +18,61 @@ use function str_replace; */ class Font { - /** - * Get list with characters and the corresponding width modifiers. - * - * @return (float|string[])[][] with characters and corresponding width modifier - */ - public function getCharLists(): array - { - return [ - //ijl - ['chars' => ['i', 'j', 'l'], 'modifier' => 0.23], - //f - ['chars' => ['f'], 'modifier' => 0.27], - //tI - ['chars' => ['t', 'I'], 'modifier' => 0.28], - //r - ['chars' => ['r'], 'modifier' => 0.34], - //1 - ['chars' => ['1'], 'modifier' => 0.49], - //cksvxyzJ - ['chars' => ['c', 'k', 's', 'v', 'x', 'y', 'z', 'J'], 'modifier' => 0.5], - //abdeghnopquL023456789 - [ - 'chars' => [ - 'a', - 'b', - 'd', - 'e', - 'g', - 'h', - 'n', - 'o', - 'p', - 'q', - 'u', - 'L', - '0', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - ], - 'modifier' => 0.56, + private const CHAR_LISTS = [ + //ijl + ['chars' => ['i', 'j', 'l'], 'modifier' => 0.23], + //f + ['chars' => ['f'], 'modifier' => 0.27], + //tI + ['chars' => ['t', 'I'], 'modifier' => 0.28], + //r + ['chars' => ['r'], 'modifier' => 0.34], + //1 + ['chars' => ['1'], 'modifier' => 0.49], + //cksvxyzJ + ['chars' => ['c', 'k', 's', 'v', 'x', 'y', 'z', 'J'], 'modifier' => 0.5], + //abdeghnopquL023456789 + [ + 'chars' => [ + 'a', + 'b', + 'd', + 'e', + 'g', + 'h', + 'n', + 'o', + 'p', + 'q', + 'u', + 'L', + '0', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', ], - //FTZ - ['chars' => ['F', 'T', 'Z'], 'modifier' => 0.61], - //ABEKPSVXY - ['chars' => ['A', 'B', 'E', 'K', 'P', 'S', 'V', 'X', 'Y'], 'modifier' => 0.67], - //wCDHNRU - ['chars' => ['w', 'C', 'D', 'H', 'N', 'R', 'U'], 'modifier' => 0.73], - //GOQ - ['chars' => ['G', 'O', 'Q'], 'modifier' => 0.78], - //mM - ['chars' => ['m', 'M'], 'modifier' => 0.84], - //W - ['chars' => ['W'], 'modifier' => 0.95], - //" " - ['chars' => [' '], 'modifier' => 0.28], - ]; - } + 'modifier' => 0.56, + ], + //FTZ + ['chars' => ['F', 'T', 'Z'], 'modifier' => 0.61], + //ABEKPSVXY + ['chars' => ['A', 'B', 'E', 'K', 'P', 'S', 'V', 'X', 'Y'], 'modifier' => 0.67], + //wCDHNRU + ['chars' => ['w', 'C', 'D', 'H', 'N', 'R', 'U'], 'modifier' => 0.73], + //GOQ + ['chars' => ['G', 'O', 'Q'], 'modifier' => 0.78], + //mM + ['chars' => ['m', 'M'], 'modifier' => 0.84], + //W + ['chars' => ['W'], 'modifier' => 0.95], + //" " + ['chars' => [' '], 'modifier' => 0.28], + ]; /** * Get width of string/text @@ -89,10 +80,9 @@ class Font * The text element width is calculated depending on font name * and font size. * - * @param string $text string of which the width will be calculated - * @param string $font name of the font like Arial,sans-serif etc - * @param int $fontSize size of font - * @param mixed[]|null $charLists list of characters and their width modifiers + * @param string $text string of which the width will be calculated + * @param string $font name of the font like Arial,sans-serif etc + * @param int $fontSize size of font * * @return int width of the text */ @@ -100,16 +90,11 @@ class Font string $text, string $font, int $fontSize, - array|null $charLists = null, ): int { - if (! isset($charLists[0]['chars'], $charLists[0]['modifier']) || ! is_array($charLists[0]['chars'])) { - $charLists = $this->getCharLists(); - } - // Start by counting the width, giving each character a modifying value $count = 0; - foreach ($charLists as $charList) { + foreach (self::CHAR_LISTS as $charList) { $count += (mb_strlen($text) - mb_strlen(str_replace($charList['chars'], '', $text)) ) * $charList['modifier']; diff --git a/tests/unit/FontTest.php b/tests/unit/FontTest.php index 2380f28908..316c566c8e 100644 --- a/tests/unit/FontTest.php +++ b/tests/unit/FontTest.php @@ -201,63 +201,4 @@ class FontTest extends AbstractTestCase $this->font->getStringWidth('phpMyAdmin', 'arial', 20), ); } - - /** - * Test getStringWidth with a custom charList. - */ - public function testGetStringWidthCharLists(): void - { - // string "a", with invalid charlist (= array without proper structure) - self::assertSame( - 6, - $this->font->getStringWidth('a', 'arial', 10, ['list']), - ); - - // string "a", with invalid charlist (= array without proper structure : - // modifier is missing - self::assertSame( - 6, - $this->font->getStringWidth( - 'a', - 'arial', - 10, - [['chars' => 'a']], - ), - ); - - // string "a", with invalid charlist (= array without proper structure : - // chars is missing - self::assertSame( - 6, - $this->font->getStringWidth( - 'a', - 'arial', - 10, - [['modifier' => 0.61]], - ), - ); - - // string "a", with invalid charlist (= array without proper structure : - // chars is not an array - self::assertSame( - 6, - $this->font->getStringWidth( - 'a', - 'arial', - 10, - [['chars' => 'a', 'modifier' => 0.61]], - ), - ); - - // string "a", with valid charlist - self::assertSame( - 7, - $this->font->getStringWidth( - 'a', - 'arial', - 10, - [['chars' => ['a'], 'modifier' => 0.61]], - ), - ); - } } From 1091f8a0d571d4df002e32353e98d554a6150e89 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 1 Sep 2026 01:11:01 +0100 Subject: [PATCH 3/4] Fix return type of ListDatabase::retrieve() Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 6 ------ psalm-baseline.xml | 3 --- src/ListDatabase.php | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7c355b299e..ccefd95bef 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -7512,12 +7512,6 @@ parameters: count: 1 path: src/ListDatabase.php - - - message: '#^Parameter \#2 \$callback of function usort expects callable\(mixed, mixed\)\: int, Closure\(string, string\)\: int\<\-1, 1\> given\.$#' - identifier: argument.type - count: 1 - path: src/ListDatabase.php - - message: ''' #^Access to deprecated static property \$route of class PhpMyAdmin\\Routing\\Routing\: diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 116dfd814a..23ce0d4b22 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4857,9 +4857,6 @@ - - - config->selectedServer['hide_db'])]]> diff --git a/src/ListDatabase.php b/src/ListDatabase.php index 0cc225c226..48eccd65e6 100644 --- a/src/ListDatabase.php +++ b/src/ListDatabase.php @@ -75,7 +75,7 @@ class ListDatabase extends ArrayObject * * @param string|null $likeDbName usually a db_name containing wildcards * - * @return mixed[] + * @return string[] */ protected function retrieve(UserPrivileges $userPrivileges, string|null $likeDbName = null): array { From c4547fc66686d87285c6c495f2e7b0983b2660fa Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 1 Sep 2026 01:52:38 +0100 Subject: [PATCH 4/4] 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 {