Skip to content

Commit

Permalink
Merge pull request #18291 from kamil-tekiela/Fix-param-type-in-setUse…
Browse files Browse the repository at this point in the history
…rValue

Fix param type in setUserValue
  • Loading branch information
MauricioFauth committed Mar 26, 2023
2 parents 7c53199 + 266f69f commit 6a183e3
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -943,11 +943,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 @@ -959,9 +954,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 @@ -14475,6 +14467,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
Original file line number Diff line number Diff line change
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 6a183e3

Please sign in to comment.