Skip to content

Commit

Permalink
Remove Config\ConfigFile global variables
Browse files Browse the repository at this point in the history
- Removes the 'cf' and 'ConfigFile' global variables.
- Extracts the ConfigFile creation from SetupPageRedirection middleware
and moves it to the Setup\SetupHelper class.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed May 11, 2024
1 parent 2fe67cc commit 52b3ef4
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 249 deletions.
145 changes: 0 additions & 145 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3025,81 +3025,26 @@ parameters:
count: 1
path: src/Controllers/Operations/ViewController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ExportController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ExportController.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ExportController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/FeaturesController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/FeaturesController.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/FeaturesController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ImportController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ImportController.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ImportController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/MainPanelController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/MainPanelController.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/MainPanelController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 2
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Cannot call method getFlatDefaultConfig\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Cannot call method resetConfigData\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Only booleans are allowed in an if condition, PhpMyAdmin\\\\Message\\|string given\\.$#"
count: 1
Expand All @@ -3115,16 +3060,6 @@ parameters:
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Parameter \\#1 \\$cf of class PhpMyAdmin\\\\Config\\\\Forms\\\\User\\\\UserFormList constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Parameter \\#1 \\$fileName of method PhpMyAdmin\\\\UserPreferences\\:\\:redirect\\(\\) expects string, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -3160,46 +3095,16 @@ parameters:
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 2
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, \\(int\\|string\\) given\\.$#"
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/NavigationController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/NavigationController.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/NavigationController.php

-
message: "#^Cannot call method getConfigArray\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Preferences/SqlController.php

-
message: "#^Parameter \\#1 \\$configArray of method PhpMyAdmin\\\\UserPreferences\\:\\:save\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Controllers/Preferences/SqlController.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -3765,56 +3670,11 @@ parameters:
count: 1
path: src/Controllers/Setup/HomeController.php

-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ConfigController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php

-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\FormController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php

-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\HomeController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php

-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ServerDestroyController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php

-
message: "#^Parameter \\#1 \\$config of class PhpMyAdmin\\\\Controllers\\\\Setup\\\\ServersController constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php

-
message: "#^Parameter \\#1 \\$filename of function file_exists expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/MainController.php

-
message: "#^Cannot call method resetConfigData\\(\\) on mixed\\.$#"
count: 1
path: src/Controllers/Setup/ShowConfigController.php

-
message: "#^Parameter \\#1 \\$cf of class PhpMyAdmin\\\\Config\\\\Forms\\\\Setup\\\\ConfigForm constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ShowConfigController.php

-
message: "#^Parameter \\#1 \\$cf of static method PhpMyAdmin\\\\Setup\\\\ConfigGenerator\\:\\:getConfigFile\\(\\) expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ShowConfigController.php

-
message: "#^Parameter \\#1 \\$cf of static method PhpMyAdmin\\\\Config\\\\Validator\\:\\:validate\\(\\) expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 1
path: src/Controllers/Setup/ValidateController.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 2
Expand Down Expand Up @@ -15235,11 +15095,6 @@ parameters:
count: 2
path: tests/unit/Config/ServerConfigChecksTest.php

-
message: "#^Parameter \\#1 \\$cfg of class PhpMyAdmin\\\\Config\\\\ServerConfigChecks constructor expects PhpMyAdmin\\\\Config\\\\ConfigFile, mixed given\\.$#"
count: 3
path: tests/unit/Config/ServerConfigChecksTest.php

-
message: "#^Property PhpMyAdmin\\\\Tests\\\\Config\\\\ServerConfigChecksTest\\:\\:\\$sessionID \\(string\\) does not accept mixed\\.$#"
count: 1
Expand Down
14 changes: 0 additions & 14 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2306,15 +2306,13 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
Expand All @@ -2328,15 +2326,13 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
Expand All @@ -2350,15 +2346,13 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
Expand All @@ -2372,15 +2366,13 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
Expand All @@ -2394,7 +2386,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['query']]]></code>
</InvalidArrayOffset>
<MixedArgument>
Expand All @@ -2407,7 +2398,6 @@
<code><![CDATA[$key]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['query']]]></code>
<code><![CDATA[$_POST[str_replace('/', '-', (string) $k)]]]></code>
<code><![CDATA[$configuration]]></code>
Expand Down Expand Up @@ -2453,15 +2443,13 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
Expand All @@ -2475,15 +2463,13 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['hash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
<code><![CDATA[$GLOBALS['tabHash']]]></code>
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
complete_query: string,
compression: 'none'|'zip'|'gzip',
conn_error: string,
ConfigFile: PhpMyAdmin\Config\ConfigFile,
csv_columns: bool,
csv_enclosed: string,
csv_escaped: string,
Expand Down
8 changes: 4 additions & 4 deletions src/Config/PageSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public function init(string $formGroupName, string|null $elemId = null): void

$this->groupName = $formGroupName;

$cf = new ConfigFile(Config::getInstance()->baseSettings);
$this->userPreferences->pageInit($cf);
$configFile = new ConfigFile(Config::getInstance()->baseSettings);
$this->userPreferences->pageInit($configFile);

$formDisplay = new $formClass($cf);
$formDisplay = new $formClass($configFile);

// Process form
$error = null;
if (isset($_POST['submit_save']) && $_POST['submit_save'] == $formGroupName) {
$error = $this->processPageSettings($formDisplay, $cf);
$error = $this->processPageSettings($formDisplay, $configFile);
}

// Display forms
Expand Down
9 changes: 4 additions & 5 deletions src/Controllers/Preferences/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ public function __construct(

public function __invoke(ServerRequest $request): Response|null
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['tabHash'] ??= null;
$GLOBALS['hash'] ??= null;

$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);

$formDisplay = new ExportForm($GLOBALS['cf'], 1);
$formDisplay = new ExportForm($configFile, 1);

if ($request->hasBodyParam('revert')) {
// revert erroneous fields to their default values
Expand All @@ -58,7 +57,7 @@ public function __invoke(ServerRequest $request): Response|null
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
$result = $this->userPreferences->save($configFile->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
Expand Down

0 comments on commit 52b3ef4

Please sign in to comment.