diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1717b2e91e..0d0e388f38 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\: @@ -7383,12 +7359,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 @@ -7542,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\: @@ -12807,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 @@ -12825,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 - @@ -12868,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 d0b14f6577..4b7366caf0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4034,31 +4034,6 @@ storage[self::STORAGE_KEY]]]> - - - - - - - - - - - - - - - - - - - - - - - @@ -4787,12 +4762,10 @@ - ]]> - - - - config->selectedServer['hide_db'])]]> @@ -7581,6 +7551,9 @@ + + + @@ -7588,37 +7561,17 @@ - - - - - - - - - - - - - - - - - - - - @@ -7631,19 +7584,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/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/src/InsertEdit.php b/src/InsertEdit.php index b4d0d0e170..2d139248aa 100644 --- a/src/InsertEdit.php +++ b/src/InsertEdit.php @@ -795,18 +795,6 @@ class InsertEdit return $gotoInclude; } - /** - * Defines the url to return in case of failure of the query - * - * @param mixed[] $urlParams url parameters - * - * @return string error url for query failure - */ - public function getErrorUrl(array $urlParams): string - { - return $_POST['err_url'] ?? Url::getFromRoute('/table/change', $urlParams); - } - /** * Executes the sql query and get the result, then move back to the calling page * 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 { 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 { 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]], - ), - ); - } } diff --git a/tests/unit/InsertEditTest.php b/tests/unit/InsertEditTest.php index c4c9b1ad7c..d57e59e8cf 100644 --- a/tests/unit/InsertEditTest.php +++ b/tests/unit/InsertEditTest.php @@ -1129,23 +1129,6 @@ class InsertEditTest extends AbstractTestCase ); } - /** - * Test for getErrorUrl - */ - public function testGetErrorUrl(): void - { - self::assertSame( - 'index.php?route=/table/change&lang=en', - $this->insertEdit->getErrorUrl([]), - ); - - $_POST['err_url'] = 'localhost'; - self::assertSame( - 'localhost', - $this->insertEdit->getErrorUrl([]), - ); - } - /** * Test for executeSqlQuery */