diff --git a/libraries/classes/Config/ConfigFile.php b/libraries/classes/Config/ConfigFile.php
index 5b99a96c97..857a8f0613 100644
--- a/libraries/classes/Config/ConfigFile.php
+++ b/libraries/classes/Config/ConfigFile.php
@@ -12,7 +12,6 @@ use PhpMyAdmin\Core;
use function array_diff;
use function array_flip;
use function array_keys;
-use function array_walk;
use function count;
use function is_array;
use function preg_replace;
@@ -83,13 +82,6 @@ class ConfigFile
*/
private $id;
- /**
- * Result for {@link flattenArray()}
- *
- * @var array|null
- */
- private $flattenArrayResult;
-
/**
* @param array|null $baseConfig base configuration read from
* {@link PhpMyAdmin\Config::$base_config},
@@ -247,48 +239,30 @@ class ConfigFile
/**
* Flattens multidimensional array, changes indices to paths
* (eg. 'key/subkey').
- * Used as array_walk() callback.
*
- * @param mixed $value Value
- * @param mixed $key Key
- * @param mixed $prefix Prefix
+ * @param array $array Multidimensional array
+ * @param string $prefix Prefix
*/
- private function flattenArray($value, $key, $prefix): void
+ private function getFlatArray(array $array, string $prefix = ''): array
{
- // no recursion for numeric arrays
- if (is_array($value) && ! isset($value[0])) {
- $prefix .= $key . '/';
- array_walk(
- $value,
- function ($value, $key, $prefix): void {
- $this->flattenArray($value, $key, $prefix);
- },
- $prefix
- );
- } else {
- $this->flattenArrayResult[$prefix . $key] = $value;
+ $result = [];
+ foreach ($array as $key => $value) {
+ if (is_array($value) && ! isset($value[0])) {
+ $result += $this->getFlatArray($value, $prefix . $key . '/');
+ } else {
+ $result[$prefix . $key] = $value;
+ }
}
+
+ return $result;
}
/**
* Returns default config in a flattened array
- *
- * @return array
*/
- public function getFlatDefaultConfig()
+ public function getFlatDefaultConfig(): array
{
- $this->flattenArrayResult = [];
- array_walk(
- $this->defaultCfg,
- function ($value, $key, $prefix): void {
- $this->flattenArray($value, $key, $prefix);
- },
- ''
- );
- $flatConfig = $this->flattenArrayResult;
- $this->flattenArrayResult = null;
-
- return $flatConfig;
+ return $this->getFlatArray($this->defaultCfg);
}
/**
@@ -300,16 +274,7 @@ class ConfigFile
public function updateWithGlobalConfig(array $cfg): void
{
// load config array and flatten it
- $this->flattenArrayResult = [];
- array_walk(
- $cfg,
- function ($value, $key, $prefix): void {
- $this->flattenArray($value, $key, $prefix);
- },
- ''
- );
- $flatConfig = $this->flattenArrayResult;
- $this->flattenArrayResult = null;
+ $flatConfig = $this->getFlatArray($cfg);
// save values map for translating a few user preferences paths,
// should be complemented by code reading from generated config
@@ -533,16 +498,7 @@ class ConfigFile
*/
public function getConfigArray()
{
- $this->flattenArrayResult = [];
- array_walk(
- $_SESSION[$this->id],
- function ($value, $key, $prefix): void {
- $this->flattenArray($value, $key, $prefix);
- },
- ''
- );
- $c = $this->flattenArrayResult;
- $this->flattenArrayResult = null;
+ $c = $this->getFlatArray($_SESSION[$this->id]);
$persistKeys = array_diff(
array_keys($this->persistKeys),
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 02f6708f53..0bf5c9534e 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -280,11 +280,6 @@ parameters:
count: 1
path: libraries/classes/Config.php
- -
- message: "#^Empty array passed to foreach\\.$#"
- count: 1
- path: libraries/classes/Config/ConfigFile.php
-
-
message: "#^Method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:__construct\\(\\) has parameter \\$baseConfig with no value type specified in iterable type array\\.$#"
count: 1
@@ -305,6 +300,16 @@ parameters:
count: 1
path: libraries/classes/Config/ConfigFile.php
+ -
+ message: "#^Method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getFlatArray\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#"
+ count: 1
+ path: libraries/classes/Config/ConfigFile.php
+
+ -
+ message: "#^Method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getFlatArray\\(\\) return type has no value type specified in iterable type array\\.$#"
+ count: 1
+ path: libraries/classes/Config/ConfigFile.php
+
-
message: "#^Method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getFlatDefaultConfig\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
@@ -375,11 +380,6 @@ parameters:
count: 1
path: libraries/classes/Config/ConfigFile.php
- -
- message: "#^Property PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:\\$flattenArrayResult type has no value type specified in iterable type array\\.$#"
- count: 1
- path: libraries/classes/Config/ConfigFile.php
-
-
message: "#^Property PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:\\$persistKeys type has no value type specified in iterable type array\\.$#"
count: 1
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index b8f8fa97e0..8efc9f6556 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -457,20 +457,6 @@
$this->cfgDb['_overrides']
-
- $key
- $key
- $key
- $key
- $prefix
- $prefix
- $prefix
- $prefix
- $value
- $value
- $value
- $value
-
$_SESSION[$this->id]
$_SESSION[$this->id]
@@ -497,11 +483,10 @@
$_SESSION[$this->id]['Servers'][$i]
-
+
$c[$mapFrom]
- $this->cfgUpdateReadMapping[$path]
-
+
$_SESSION[$this->id]['Servers'][$i]
$c
$c[$k]
@@ -513,8 +498,9 @@
$mapFrom
$path
$path
- $path
$port
+ $result[$prefix . $key]
+ $value
$value
$value
$verbose
@@ -524,11 +510,8 @@
array
string
-
- $key
+
$port
- $prefix
- $prefix
$this->getValue($path . '/host')
$this->getValue($path . '/socket')
$this->getValue($path . '/user')