Skip to content

Commit

Permalink
Fix param type in setUserValue
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Mar 25, 2023
1 parent de952c7 commit 266f69f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
6 changes: 3 additions & 3 deletions libraries/classes/Config.php
Expand Up @@ -534,15 +534,15 @@ 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
*/
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']);
Expand All @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions phpstan-baseline.neon
Expand Up @@ -162,7 +162,7 @@ parameters:

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
count: 2
path: libraries/classes/Config.php

-
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions psalm-baseline.xml
Expand Up @@ -944,11 +944,6 @@
<code>readgzfile</code>
</UnusedFunctionCall>
</file>
<file src="libraries/classes/Controllers/CollationConnectionController.php">
<MixedArgument>
<code><![CDATA[$request->getParsedBodyParam('collation_connection')]]></code>
</MixedArgument>
</file>
<file src="libraries/classes/Controllers/ColumnController.php">
<PossiblyUnusedMethod>
<code>__construct</code>
Expand All @@ -960,9 +955,6 @@
</PossiblyUnusedMethod>
</file>
<file src="libraries/classes/Controllers/Config/SetConfigController.php">
<MixedArgument>
<code>json_decode($value)</code>
</MixedArgument>
<PossiblyUnusedMethod>
<code>__construct</code>
</PossiblyUnusedMethod>
Expand Down Expand Up @@ -14477,6 +14469,9 @@
<InvalidArgument>
<code>$v</code>
</InvalidArgument>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cfg']['NavigationWidth']]]></code>
</InvalidArrayOffset>
<InvalidCast>
<code>$v</code>
</InvalidCast>
Expand Down
5 changes: 5 additions & 0 deletions test/classes/ConfigTest.php
Expand Up @@ -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,
);
}

/**
Expand Down

0 comments on commit 266f69f

Please sign in to comment.