From c948030634eafccea4ff0300ca05ded7c6b18042 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 27 May 2023 20:00:31 +0100 Subject: [PATCH 1/5] $GLOBALS['form_display'] Signed-off-by: Kamil Tekiela --- .../Controllers/Preferences/ManageController.php | 11 +++++------ psalm-baseline.xml | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/classes/Controllers/Preferences/ManageController.php b/libraries/classes/Controllers/Preferences/ManageController.php index 53249c067f..f5714e4bd5 100644 --- a/libraries/classes/Controllers/Preferences/ManageController.php +++ b/libraries/classes/Controllers/Preferences/ManageController.php @@ -64,7 +64,6 @@ class ManageController extends AbstractController $GLOBALS['lang'] ??= null; $GLOBALS['new_config'] ??= null; $GLOBALS['return_url'] ??= null; - $GLOBALS['form_display'] ??= null; $GLOBALS['all_ok'] ??= null; $GLOBALS['query'] ??= null; @@ -147,7 +146,7 @@ class ManageController extends AbstractController } else { // sanitize input values: treat them as though // they came from HTTP POST request - $GLOBALS['form_display'] = new UserFormList($GLOBALS['cf']); + $formDisplay = new UserFormList($GLOBALS['cf']); $GLOBALS['new_config'] = $GLOBALS['cf']->getFlatDefaultConfig(); if ($request->hasBodyParam('import_merge')) { $GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $GLOBALS['cf']->getConfigArray()); @@ -160,12 +159,12 @@ class ManageController extends AbstractController } $GLOBALS['cf']->resetConfigData(); - $GLOBALS['all_ok'] = $GLOBALS['form_display']->process(true, false); - $GLOBALS['all_ok'] = $GLOBALS['all_ok'] && ! $GLOBALS['form_display']->hasErrors(); + $GLOBALS['all_ok'] = $formDisplay->process(true, false); + $GLOBALS['all_ok'] = $GLOBALS['all_ok'] && ! $formDisplay->hasErrors(); $_POST = $postParamBackup; if (! $GLOBALS['all_ok'] && $request->hasBodyParam('fix_errors')) { - $GLOBALS['form_display']->fixErrors(); + $formDisplay->fixErrors(); $GLOBALS['all_ok'] = true; } @@ -180,7 +179,7 @@ class ManageController extends AbstractController ]); echo $this->template->render('preferences/manage/error', [ - 'form_errors' => $GLOBALS['form_display']->displayErrors(), + 'form_errors' => $formDisplay->displayErrors(), 'json' => $GLOBALS['json'], 'import_merge' => $request->getParsedBodyParam('import_merge'), 'return_url' => $GLOBALS['return_url'], diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5d39590c72..725d4257ee 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2418,7 +2418,6 @@ - @@ -2437,7 +2436,6 @@ - From 9e35b7b113a2ba98b293e98a91c54f2b9f9486e1 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 27 May 2023 20:01:57 +0100 Subject: [PATCH 2/5] $GLOBALS['all_ok'] Signed-off-by: Kamil Tekiela --- .../Controllers/Preferences/ManageController.php | 11 +++++------ psalm-baseline.xml | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/classes/Controllers/Preferences/ManageController.php b/libraries/classes/Controllers/Preferences/ManageController.php index f5714e4bd5..4e38619619 100644 --- a/libraries/classes/Controllers/Preferences/ManageController.php +++ b/libraries/classes/Controllers/Preferences/ManageController.php @@ -64,7 +64,6 @@ class ManageController extends AbstractController $GLOBALS['lang'] ??= null; $GLOBALS['new_config'] ??= null; $GLOBALS['return_url'] ??= null; - $GLOBALS['all_ok'] ??= null; $GLOBALS['query'] ??= null; $route = $request->getRoute(); @@ -159,16 +158,16 @@ class ManageController extends AbstractController } $GLOBALS['cf']->resetConfigData(); - $GLOBALS['all_ok'] = $formDisplay->process(true, false); - $GLOBALS['all_ok'] = $GLOBALS['all_ok'] && ! $formDisplay->hasErrors(); + $allOk = $formDisplay->process(true, false); + $allOk = $allOk && ! $formDisplay->hasErrors(); $_POST = $postParamBackup; - if (! $GLOBALS['all_ok'] && $request->hasBodyParam('fix_errors')) { + if (! $allOk && $request->hasBodyParam('fix_errors')) { $formDisplay->fixErrors(); - $GLOBALS['all_ok'] = true; + $allOk = true; } - if (! $GLOBALS['all_ok']) { + if (! $allOk) { // mimic original form and post json in a hidden field $relationParameters = $this->relation->getRelationParameters(); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 725d4257ee..c348f34cae 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2416,7 +2416,6 @@ - @@ -2434,7 +2433,6 @@ $key - From 9d931c878d0e44e4d91558a7f774f97371f7e67c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 27 May 2023 20:06:05 +0100 Subject: [PATCH 3/5] $GLOBALS['return_url'] Signed-off-by: Kamil Tekiela --- .../Controllers/Preferences/ManageController.php | 15 +++++++-------- phpstan-baseline.neon | 10 ++++++++++ psalm-baseline.xml | 7 ++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libraries/classes/Controllers/Preferences/ManageController.php b/libraries/classes/Controllers/Preferences/ManageController.php index 4e38619619..48efb5ddb3 100644 --- a/libraries/classes/Controllers/Preferences/ManageController.php +++ b/libraries/classes/Controllers/Preferences/ManageController.php @@ -63,7 +63,6 @@ class ManageController extends AbstractController $GLOBALS['json'] ??= null; $GLOBALS['lang'] ??= null; $GLOBALS['new_config'] ??= null; - $GLOBALS['return_url'] ??= null; $GLOBALS['query'] ??= null; $route = $request->getRoute(); @@ -137,7 +136,7 @@ class ManageController extends AbstractController $_SESSION['userprefs_autoload'] = true; $configuration = json_decode($GLOBALS['json'], true); - $GLOBALS['return_url'] = $request->getParsedBodyParam('return_url'); + $returnUrl = $request->getParsedBodyParam('return_url'); if (! is_array($configuration)) { if (! isset($GLOBALS['error'])) { $GLOBALS['error'] = __('Could not import configuration'); @@ -181,7 +180,7 @@ class ManageController extends AbstractController 'form_errors' => $formDisplay->displayErrors(), 'json' => $GLOBALS['json'], 'import_merge' => $request->getParsedBodyParam('import_merge'), - 'return_url' => $GLOBALS['return_url'], + 'return_url' => $returnUrl, ]); return; @@ -205,9 +204,9 @@ class ManageController extends AbstractController // save settings $result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray()); if ($result === true) { - if ($GLOBALS['return_url']) { - $GLOBALS['query'] = Util::splitURLQuery($GLOBALS['return_url']); - $GLOBALS['return_url'] = parse_url($GLOBALS['return_url'], PHP_URL_PATH); + if ($returnUrl) { + $GLOBALS['query'] = Util::splitURLQuery($returnUrl); + $returnUrl = parse_url($returnUrl, PHP_URL_PATH); foreach ($GLOBALS['query'] as $q) { $pos = mb_strpos($q, '='); @@ -219,12 +218,12 @@ class ManageController extends AbstractController $redirectParams[$k] = mb_substr($q, $pos + 1); } } else { - $GLOBALS['return_url'] = 'index.php?route=/preferences/manage'; + $returnUrl = 'index.php?route=/preferences/manage'; } // reload config $this->config->loadUserPreferences($this->themeManager); - $this->userPreferences->redirect($GLOBALS['return_url'] ?? '', $redirectParams); + $this->userPreferences->redirect($returnUrl ?? '', $redirectParams); return; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9aafd09bea..335fac3e2d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1675,6 +1675,16 @@ parameters: count: 1 path: libraries/classes/Controllers/Preferences/ManageController.php + - + message: "#^Parameter \\#1 \\$url of function parse_url expects string, mixed given\\.$#" + count: 1 + path: libraries/classes/Controllers/Preferences/ManageController.php + + - + message: "#^Parameter \\#1 \\$url of static method PhpMyAdmin\\\\Util\\:\\:splitURLQuery\\(\\) expects string, mixed given\\.$#" + count: 1 + path: libraries/classes/Controllers/Preferences/ManageController.php + - message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, \\(int\\|string\\) given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c348f34cae..2de76c7a47 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2420,14 +2420,12 @@ - - - + $returnUrl $key @@ -2438,11 +2436,10 @@ - - $configuration + $returnUrl $v $val From 84136fa2bb2b54660c056cdce658c5e545aea96c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 27 May 2023 20:08:22 +0100 Subject: [PATCH 4/5] $GLOBALS['new_config'] Signed-off-by: Kamil Tekiela --- .../classes/Controllers/Preferences/ManageController.php | 9 ++++----- psalm-baseline.xml | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/classes/Controllers/Preferences/ManageController.php b/libraries/classes/Controllers/Preferences/ManageController.php index 48efb5ddb3..97643a7a42 100644 --- a/libraries/classes/Controllers/Preferences/ManageController.php +++ b/libraries/classes/Controllers/Preferences/ManageController.php @@ -62,7 +62,6 @@ class ManageController extends AbstractController $GLOBALS['error'] ??= null; $GLOBALS['json'] ??= null; $GLOBALS['lang'] ??= null; - $GLOBALS['new_config'] ??= null; $GLOBALS['query'] ??= null; $route = $request->getRoute(); @@ -145,14 +144,14 @@ class ManageController extends AbstractController // sanitize input values: treat them as though // they came from HTTP POST request $formDisplay = new UserFormList($GLOBALS['cf']); - $GLOBALS['new_config'] = $GLOBALS['cf']->getFlatDefaultConfig(); + $newConfig = $GLOBALS['cf']->getFlatDefaultConfig(); if ($request->hasBodyParam('import_merge')) { - $GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $GLOBALS['cf']->getConfigArray()); + $newConfig = array_merge($newConfig, $GLOBALS['cf']->getConfigArray()); } - $GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $configuration); + $newConfig = array_merge($newConfig, $configuration); $postParamBackup = $_POST; - foreach ($GLOBALS['new_config'] as $k => $v) { + foreach ($newConfig as $k => $v) { $_POST[str_replace('/', '-', (string) $k)] = $v; } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2de76c7a47..3a95d1f909 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2418,7 +2418,6 @@ - @@ -2434,7 +2433,6 @@ - $configuration From 3534027732e14295d7d1d8fb5a89508f9529b728 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 27 May 2023 20:12:45 +0100 Subject: [PATCH 5/5] $GLOBALS['json'] Signed-off-by: Kamil Tekiela --- .../Controllers/Preferences/ManageController.php | 11 +++++------ phpstan-baseline.neon | 5 +++++ psalm-baseline.xml | 8 +++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/classes/Controllers/Preferences/ManageController.php b/libraries/classes/Controllers/Preferences/ManageController.php index 97643a7a42..f51c5d68f6 100644 --- a/libraries/classes/Controllers/Preferences/ManageController.php +++ b/libraries/classes/Controllers/Preferences/ManageController.php @@ -60,7 +60,6 @@ class ManageController extends AbstractController { $GLOBALS['cf'] ??= null; $GLOBALS['error'] ??= null; - $GLOBALS['json'] ??= null; $GLOBALS['lang'] ??= null; $GLOBALS['query'] ??= null; @@ -107,7 +106,7 @@ class ManageController extends AbstractController if ($request->hasBodyParam('submit_import')) { // load from JSON file - $GLOBALS['json'] = ''; + $json = ''; if ( $request->hasBodyParam('import_type') && $request->getParsedBodyParam('import_type') === 'text_file' @@ -124,17 +123,17 @@ class ManageController extends AbstractController $GLOBALS['error'] = $importHandle->getError(); } else { // read JSON from uploaded file - $GLOBALS['json'] = $importHandle->getRawContent(); + $json = $importHandle->getRawContent(); } } else { // read from POST value (json) - $GLOBALS['json'] = $request->getParsedBodyParam('json'); + $json = $request->getParsedBodyParam('json'); } // hide header message $_SESSION['userprefs_autoload'] = true; - $configuration = json_decode($GLOBALS['json'], true); + $configuration = json_decode($json, true); $returnUrl = $request->getParsedBodyParam('return_url'); if (! is_array($configuration)) { if (! isset($GLOBALS['error'])) { @@ -177,7 +176,7 @@ class ManageController extends AbstractController echo $this->template->render('preferences/manage/error', [ 'form_errors' => $formDisplay->displayErrors(), - 'json' => $GLOBALS['json'], + 'json' => $json, 'import_merge' => $request->getParsedBodyParam('import_merge'), 'return_url' => $returnUrl, ]); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 335fac3e2d..9850e997da 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1675,6 +1675,11 @@ parameters: count: 1 path: libraries/classes/Controllers/Preferences/ManageController.php + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, mixed given\\.$#" + count: 1 + path: libraries/classes/Controllers/Preferences/ManageController.php + - message: "#^Parameter \\#1 \\$url of function parse_url expects string, mixed given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 3a95d1f909..2d21b2bed8 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2417,13 +2417,12 @@ - - + $json $returnUrl @@ -2431,18 +2430,17 @@ - - $configuration + $json $returnUrl $v $val - + $json $pos