From 266f69ffb6be467b026193f5e5db9f53b95473ae Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 25 Mar 2023 13:48:05 +0000 Subject: [PATCH] Fix param type in setUserValue Signed-off-by: Kamil Tekiela --- libraries/classes/Config.php | 6 +++--- phpstan-baseline.neon | 12 +----------- psalm-baseline.xml | 11 +++-------- test/classes/ConfigTest.php | 5 +++++ 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php index 6a410466ec32..9c1046623079 100644 --- a/libraries/classes/Config.php +++ b/libraries/classes/Config.php @@ -534,7 +534,7 @@ public function loadUserPreferences(bool $isMinimumCommon = false): void * * @param string|null $cookie_name can be null * @param string $cfg_path configuration path - * @param string $new_cfg_value new value + * @param mixed $new_cfg_value new value * @param string|null $default_value default value * * @return true|Message @@ -542,7 +542,7 @@ public function loadUserPreferences(bool $isMinimumCommon = false): void public function setUserValue( string|null $cookie_name, string $cfg_path, - string $new_cfg_value, + mixed $new_cfg_value, string|null $default_value = null, ): bool|Message { $userPreferences = new UserPreferences($GLOBALS['dbi']); @@ -563,7 +563,7 @@ public function setUserValue( $default_value = Core::arrayRead($cfg_path, $this->settings); } - $this->setCookie($cookie_name, $new_cfg_value, $default_value); + $this->setCookie($cookie_name, (string) $new_cfg_value, $default_value); } Core::arrayWrite($cfg_path, $GLOBALS['cfg'], $new_cfg_value); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4495ba51980c..e1df55120d9c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -162,7 +162,7 @@ parameters: - message: "#^Cannot cast mixed to string\\.$#" - count: 1 + count: 2 path: libraries/classes/Config.php - @@ -990,16 +990,6 @@ parameters: count: 1 path: libraries/classes/Controllers/AbstractController.php - - - message: "#^Parameter \\#3 \\$new_cfg_value of method PhpMyAdmin\\\\Config\\:\\:setUserValue\\(\\) expects string, mixed given\\.$#" - count: 1 - path: libraries/classes/Controllers/CollationConnectionController.php - - - - message: "#^Parameter \\#3 \\$new_cfg_value of method PhpMyAdmin\\\\Config\\:\\:setUserValue\\(\\) expects string, mixed given\\.$#" - count: 1 - path: libraries/classes/Controllers/Config/SetConfigController.php - - message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getColumnsNotInCentralList\\(\\) expects string, mixed given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d8f7c580636b..748311a6df91 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -944,11 +944,6 @@ readgzfile - - - getParsedBodyParam('collation_connection')]]> - - __construct @@ -960,9 +955,6 @@ - - json_decode($value) - __construct @@ -14477,6 +14469,9 @@ $v + + + $v diff --git a/test/classes/ConfigTest.php b/test/classes/ConfigTest.php index 363803f602a1..686aa625204f 100644 --- a/test/classes/ConfigTest.php +++ b/test/classes/ConfigTest.php @@ -941,6 +941,11 @@ public function testSetUserValue(): void $this->object->getUserValue('TEST_COOKIE_USER_VAL', 'fail'), 'cfg_val_1', ); + $this->object->setUserValue(null, 'NavigationWidth', 300); + $this->assertSame( + $GLOBALS['cfg']['NavigationWidth'], + 300, + ); } /**