Skip to content

Commit 0cc1955

Browse files
committed
Merge #20039 Major cleanup of config
The commit "Remove ldi_local_option setting" was removed. Closes #20039 Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
2 parents 93488cc + 95c707d commit 0cc1955

File tree

68 files changed

+129
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+129
-309
lines changed

phpstan-baseline.neon

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,7 @@ parameters:
313313
path: src/Config.php
314314

315315
-
316-
message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept array\.$#'
317-
identifier: assign.propertyType
318-
count: 1
319-
path: src/Config.php
320-
321-
-
322-
message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept non\-empty\-array\<string, mixed\>\.$#'
316+
message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept array\<mixed\>\.$#'
323317
identifier: assign.propertyType
324318
count: 1
325319
path: src/Config.php
@@ -951,12 +945,6 @@ parameters:
951945
count: 5
952946
path: src/Config/UserPreferencesHandler.php
953947

954-
-
955-
message: '#^Cannot access offset ''userprefs_mtime'' on mixed\.$#'
956-
identifier: offsetAccess.nonOffsetAccessible
957-
count: 2
958-
path: src/Config/UserPreferencesHandler.php
959-
960948
-
961949
message: '#^Cannot access offset ''userprefs_type'' on mixed\.$#'
962950
identifier: offsetAccess.nonOffsetAccessible
@@ -1011,12 +999,6 @@ parameters:
1011999
count: 1
10121000
path: src/Config/UserPreferencesHandler.php
10131001

1014-
-
1015-
message: '#^Property PhpMyAdmin\\Config\:\:\$settings \(array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\}\) does not accept array\<mixed\>\.$#'
1016-
identifier: assign.propertyType
1017-
count: 1
1018-
path: src/Config/UserPreferencesHandler.php
1019-
10201002
-
10211003
message: '#^Property PhpMyAdmin\\Config\\UserPreferencesHandler\:\:\$storageType \(''''\|''db''\|''session''\) does not accept mixed\.$#'
10221004
identifier: assign.propertyType
@@ -13809,15 +13791,6 @@ parameters:
1380913791
count: 1
1381013792
path: tests/test_data/config.inc.php
1381113793

13812-
-
13813-
message: '''
13814-
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
13815-
Use dependency injection instead\.$#
13816-
'''
13817-
identifier: staticMethod.deprecated
13818-
count: 1
13819-
path: tests/unit/AbstractTestCase.php
13820-
1382113794
-
1382213795
message: '''
1382313796
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\:
@@ -14301,15 +14274,6 @@ parameters:
1430114274
count: 5
1430214275
path: tests/unit/ConfigStorage/RelationTest.php
1430314276

14304-
-
14305-
message: '''
14306-
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
14307-
Use dependency injection instead\.$#
14308-
'''
14309-
identifier: staticMethod.deprecated
14310-
count: 1
14311-
path: tests/unit/ConfigTest.php
14312-
1431314277
-
1431414278
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''Server'' and array\{PmaAbsoluteUri\: string, AuthLog\: string, AuthLogSuccess\: bool, PmaNoRelation_DisableWarning\: bool, SuhosinDisableWarning\: bool, LoginCookieValidityDisableWarning\: bool, ReservedWordDisableWarning\: bool, TranslationWarningThreshold\: int, \.\.\.\} will always evaluate to false\.$#'
1431514279
identifier: staticMethod.impossibleType
@@ -16851,12 +16815,6 @@ parameters:
1685116815
count: 1
1685216816
path: tests/unit/TwoFactorTest.php
1685316817

16854-
-
16855-
message: '#^Missing call to parent\:\:tearDown\(\) method\.$#'
16856-
identifier: phpunit.callParent
16857-
count: 1
16858-
path: tests/unit/TwoFactorTest.php
16859-
1686016818
-
1686116819
message: '#^Parameter \#1 \$secret of method PragmaRX\\Google2FA\\Google2FA\:\:oathTotp\(\) expects string, mixed given\.$#'
1686216820
identifier: argument.type
@@ -16921,7 +16879,7 @@ parameters:
1692116879
path: tests/unit/UtilTest.php
1692216880

1692316881
-
16924-
message: '#^Cannot access offset ''server_2'' on mixed\.$#'
16882+
message: '#^Cannot access offset ''server_2_'' on mixed\.$#'
1692516883
identifier: offsetAccess.nonOffsetAccessible
1692616884
count: 4
1692716885
path: tests/unit/UtilTest.php
@@ -16932,12 +16890,6 @@ parameters:
1693216890
count: 2
1693316891
path: tests/unit/UtilTest.php
1693416892

16935-
-
16936-
message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#'
16937-
identifier: assign.propertyType
16938-
count: 1
16939-
path: tests/unit/UtilTest.php
16940-
1694116893
-
1694216894
message: '''
1694316895
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
@@ -16999,7 +16951,7 @@ parameters:
1699916951
path: tests/unit/Utils/SessionCacheTest.php
1700016952

1700116953
-
17002-
message: '#^Cannot access offset ''server_2'' on mixed\.$#'
16954+
message: '#^Cannot access offset ''server_2_'' on mixed\.$#'
1700316955
identifier: offsetAccess.nonOffsetAccessible
1700416956
count: 4
1700516957
path: tests/unit/Utils/SessionCacheTest.php
@@ -17028,12 +16980,6 @@ parameters:
1702816980
count: 2
1702916981
path: tests/unit/Utils/SessionCacheTest.php
1703016982

17031-
-
17032-
message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#'
17033-
identifier: assign.propertyType
17034-
count: 5
17035-
path: tests/unit/Utils/SessionCacheTest.php
17036-
1703716983
-
1703816984
message: '''
1703916985
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:

psalm-baseline.xml

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@
118118
<code><![CDATA[$this->settings]]></code>
119119
<code><![CDATA[$this->settings]]></code>
120120
</InvalidPropertyAssignmentValue>
121+
<MixedAssignment>
122+
<code><![CDATA[$array[$part]]]></code>
123+
</MixedAssignment>
121124
<MixedPropertyTypeCoercion>
122-
<code><![CDATA[array_replace_recursive($this->settings, $this->config->asArray())]]></code>
125+
<code><![CDATA[$this->settings]]></code>
123126
</MixedPropertyTypeCoercion>
124127
<PossiblyInvalidArrayOffset>
125128
<code><![CDATA[$_COOKIE[$this->getCookieName($cookieName)]]]></code>
126129
</PossiblyInvalidArrayOffset>
127-
<PropertyTypeCoercion>
128-
<code><![CDATA[$this->settings]]></code>
129-
</PropertyTypeCoercion>
130130
<RiskyTruthyFalsyComparison>
131131
<code><![CDATA[empty($path)]]></code>
132132
</RiskyTruthyFalsyComparison>
@@ -420,18 +420,15 @@
420420
<MixedArrayAccess>
421421
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs']]]></code>
422422
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs']['LoginCookieValidity']]]></code>
423-
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs_mtime']]]></code>
424423
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs_type']]]></code>
425424
<code><![CDATA[$configData['lang']]]></code>
426425
</MixedArrayAccess>
427426
<MixedArrayAssignment>
428427
<code><![CDATA[$_SESSION['cache'][$cacheKey]]]></code>
429428
<code><![CDATA[$_SESSION['cache'][$cacheKey]]]></code>
430429
<code><![CDATA[$_SESSION['cache'][$cacheKey]]]></code>
431-
<code><![CDATA[$_SESSION['cache'][$cacheKey]]]></code>
432430
<code><![CDATA[$_SESSION['cache'][$cacheKey]['config_mtime']]]></code>
433431
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs']]]></code>
434-
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs_mtime']]]></code>
435432
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs_type']]]></code>
436433
</MixedArrayAssignment>
437434
<MixedAssignment>
@@ -442,7 +439,6 @@
442439
<code><![CDATA[$value]]></code>
443440
</MixedAssignment>
444441
<MixedPropertyTypeCoercion>
445-
<code><![CDATA[$this->config->settings]]></code>
446442
<code><![CDATA[array_replace_recursive($this->config->settings, $configData)]]></code>
447443
</MixedPropertyTypeCoercion>
448444
<PossiblyInvalidArgument>
@@ -8792,9 +8788,6 @@
87928788
</TypeDoesNotContainNull>
87938789
</file>
87948790
<file src="tests/unit/AbstractTestCase.php">
8795-
<DeprecatedMethod>
8796-
<code><![CDATA[Config::getInstance()]]></code>
8797-
</DeprecatedMethod>
87988791
<PossiblyUndefinedArrayOffset>
87998792
<code><![CDATA[$_SERVER['PHP_SELF']]]></code>
88008793
<code><![CDATA[$_SERVER['REQUEST_TIME']]]></code>
@@ -9151,9 +9144,6 @@
91519144
</TypeDoesNotContainType>
91529145
</file>
91539146
<file src="tests/unit/ConfigTest.php">
9154-
<DeprecatedMethod>
9155-
<code><![CDATA[Config::getInstance()]]></code>
9156-
</DeprecatedMethod>
91579147
<InvalidArrayOffset>
91589148
<code><![CDATA[$config->settings['Server']]]></code>
91599149
<code><![CDATA[$config->settings['Server']]]></code>
@@ -10836,20 +10826,17 @@
1083610826
<code><![CDATA[Config::getInstance()]]></code>
1083710827
<code><![CDATA[Config::getInstance()]]></code>
1083810828
</DeprecatedMethod>
10839-
<InvalidPropertyAssignmentValue>
10840-
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
10841-
</InvalidPropertyAssignmentValue>
1084210829
<MixedArgument>
10843-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10844-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10830+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10831+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
1084510832
</MixedArgument>
1084610833
<MixedArrayAccess>
10847-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10848-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10849-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10850-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10851-
<code><![CDATA[$_SESSION['cache']['server_2']['is_superuser']]]></code>
10852-
<code><![CDATA[$_SESSION['cache']['server_2']['mysql_cur_user']]]></code>
10834+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10835+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10836+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10837+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10838+
<code><![CDATA[$_SESSION['cache']['server_2_']['is_superuser']]]></code>
10839+
<code><![CDATA[$_SESSION['cache']['server_2_']['mysql_cur_user']]]></code>
1085310840
</MixedArrayAccess>
1085410841
<PossiblyInvalidArgument>
1085510842
<code><![CDATA[testBackquote]]></code>
@@ -10922,24 +10909,17 @@
1092210909
<code><![CDATA[$_SESSION['cache']]]></code>
1092310910
<code><![CDATA[$_SESSION['cache']]]></code>
1092410911
</EmptyArrayAccess>
10925-
<InvalidPropertyAssignmentValue>
10926-
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
10927-
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
10928-
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
10929-
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
10930-
<code><![CDATA[Config::getInstance()->selectedServer]]></code>
10931-
</InvalidPropertyAssignmentValue>
1093210912
<MixedArgument>
10933-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10934-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10913+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10914+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
1093510915
</MixedArgument>
1093610916
<MixedArrayAccess>
10937-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10938-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10939-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10940-
<code><![CDATA[$_SESSION['cache']['server_2']]]></code>
10941-
<code><![CDATA[$_SESSION['cache']['server_2']['test_data']]]></code>
10942-
<code><![CDATA[$_SESSION['cache']['server_2']['test_data_3']]]></code>
10917+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10918+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10919+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10920+
<code><![CDATA[$_SESSION['cache']['server_2_']]]></code>
10921+
<code><![CDATA[$_SESSION['cache']['server_2_']['test_data']]]></code>
10922+
<code><![CDATA[$_SESSION['cache']['server_2_']['test_data_3']]]></code>
1094310923
</MixedArrayAccess>
1094410924
</file>
1094510925
<file src="tests/unit/VersionInformationTest.php">

src/Config.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use function __;
1515
use function array_key_last;
16-
use function array_replace_recursive;
16+
use function array_shift;
1717
use function array_slice;
1818
use function count;
1919
use function defined;
@@ -68,9 +68,6 @@ class Config
6868
{
6969
public static self|null $instance = null;
7070

71-
/** @var mixed[] default configuration settings */
72-
public array $default;
73-
7471
/** @var mixed[] configuration settings, without user preferences applied */
7572
public array $baseSettings;
7673

@@ -102,7 +99,6 @@ public function __construct()
10299
{
103100
$this->config = new Settings([]);
104101
$config = $this->config->asArray();
105-
$this->default = $config;
106102
$this->settings = $config;
107103
$this->baseSettings = $config;
108104
$this->selectedServer = (new Server())->asArray();
@@ -208,7 +204,7 @@ private function load(): void
208204
}
209205

210206
$this->config = new Settings($cfg);
211-
$this->settings = array_replace_recursive($this->settings, $this->config->asArray());
207+
$this->settings = $this->config->asArray();
212208
}
213209

214210
/**
@@ -288,15 +284,44 @@ public function checkPermissions(): void
288284
*
289285
* @param string $setting configuration option
290286
* @param mixed $value new value for configuration option
287+
*
288+
* @throws ConfigException
291289
*/
292290
public function set(string $setting, mixed $value): void
293291
{
294-
if (isset($this->settings[$setting]) && $this->settings[$setting] === $value) {
292+
$parts = explode('/', $setting);
293+
if (! $this->setValueRecursive($this->settings, $parts, $value)) {
295294
return;
296295
}
297296

298-
$this->settings[$setting] = $value;
299297
$this->config = new Settings($this->settings);
298+
$this->settings = $this->config->asArray();
299+
}
300+
301+
/**
302+
* @param mixed[] $array
303+
* @param array-key[] $parts
304+
*
305+
* @throws ConfigException
306+
*/
307+
private function setValueRecursive(array &$array, array $parts, mixed $value): bool
308+
{
309+
$part = array_shift($parts);
310+
if ($parts === []) {
311+
if ($array[$part] === $value) {
312+
return false;
313+
}
314+
315+
$array[$part] = $value;
316+
317+
return true;
318+
}
319+
320+
if (! is_array($array[$part])) {
321+
throw new ConfigException('Failed to set configuration value.');
322+
}
323+
324+
return $this->setValueRecursive($array[$part], $parts, $value);
300325
}
301326

302327
/**

0 commit comments

Comments
 (0)