diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 04d00f7d2a..aaf8c66b24 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -2206,7 +2206,7 @@ parameters:
path: src/Controllers/Preferences/ManageController.php
-
- message: '#^Parameter \#1 \$fileName of method PhpMyAdmin\\Config\\UserPreferences\:\:redirect\(\) expects string, string\|false given\.$#'
+ message: '#^Parameter \#1 \$fileName of method PhpMyAdmin\\Config\\UserPreferences\:\:getUrlToRedirect\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Preferences/ManageController.php
@@ -14202,7 +14202,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
- count: 8
+ count: 7
path: tests/unit/Config/UserPreferencesTest.php
-
@@ -14211,7 +14211,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
- count: 8
+ count: 7
path: tests/unit/Config/UserPreferencesTest.php
-
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index f1d9cbd08e..f1f4d26945 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -8996,8 +8996,6 @@
-
-
diff --git a/src/Config/UserPreferences.php b/src/Config/UserPreferences.php
index f1a303b689..4b116f4920 100644
--- a/src/Config/UserPreferences.php
+++ b/src/Config/UserPreferences.php
@@ -11,10 +11,8 @@ use PhpMyAdmin\Core;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
-use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
-use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
@@ -266,18 +264,16 @@ readonly class UserPreferences
}
/**
- * Redirects after saving new user preferences
+ * Get URL to redirect after saving new user preferences.
*
* @param string $fileName Filename
* @param mixed[]|null $params URL parameters
* @param string|null $hash Hash value
+ *
+ * @return non-empty-string
*/
- public function redirect(
- string $fileName,
- array|null $params = null,
- string|null $hash = null,
- ): Response {
- // redirect
+ public function getUrlToRedirect(string $fileName, array|null $params = null, string|null $hash = null): string
+ {
$urlParams = ['saved' => 1];
if (is_array($params)) {
$urlParams = array_merge($params, $urlParams);
@@ -287,12 +283,7 @@ readonly class UserPreferences
$hash = '#' . urlencode($hash);
}
- $responseRenderer = ResponseRenderer::getInstance();
- $responseRenderer->redirect(
- './' . $fileName . Url::getCommonRaw($urlParams, ! str_contains($fileName, '?') ? '?' : '&') . $hash,
- );
-
- return $responseRenderer->response();
+ return './' . $fileName . Url::getCommonRaw($urlParams, ! str_contains($fileName, '?') ? '?' : '&') . $hash;
}
/**
diff --git a/src/Controllers/Preferences/ExportController.php b/src/Controllers/Preferences/ExportController.php
index e589dbe0ab..ab4e8e9412 100644
--- a/src/Controllers/Preferences/ExportController.php
+++ b/src/Controllers/Preferences/ExportController.php
@@ -62,7 +62,11 @@ final readonly class ExportController implements InvocableController
$this->userPreferencesHandler->loadUserPreferences();
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
- return $this->userPreferences->redirect('index.php?route=/preferences/export', null, $hash);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/export', null, $hash),
+ );
+
+ return $this->response->response();
}
}
diff --git a/src/Controllers/Preferences/FeaturesController.php b/src/Controllers/Preferences/FeaturesController.php
index c31c28487c..de4515a9ad 100644
--- a/src/Controllers/Preferences/FeaturesController.php
+++ b/src/Controllers/Preferences/FeaturesController.php
@@ -62,7 +62,11 @@ final readonly class FeaturesController implements InvocableController
$this->userPreferencesHandler->loadUserPreferences();
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
- return $this->userPreferences->redirect('index.php?route=/preferences/features', null, $hash);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/features', null, $hash),
+ );
+
+ return $this->response->response();
}
}
diff --git a/src/Controllers/Preferences/ImportController.php b/src/Controllers/Preferences/ImportController.php
index 02ef798ecb..473dba5e3a 100644
--- a/src/Controllers/Preferences/ImportController.php
+++ b/src/Controllers/Preferences/ImportController.php
@@ -62,7 +62,11 @@ final readonly class ImportController implements InvocableController
$this->userPreferencesHandler->loadUserPreferences();
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
- return $this->userPreferences->redirect('index.php?route=/preferences/import', null, $hash);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/import', null, $hash),
+ );
+
+ return $this->response->response();
}
}
diff --git a/src/Controllers/Preferences/MainPanelController.php b/src/Controllers/Preferences/MainPanelController.php
index 5968f66d33..f611f9f030 100644
--- a/src/Controllers/Preferences/MainPanelController.php
+++ b/src/Controllers/Preferences/MainPanelController.php
@@ -62,7 +62,11 @@ final readonly class MainPanelController implements InvocableController
$this->userPreferencesHandler->loadUserPreferences();
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
- return $this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $hash);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/main-panel', null, $hash),
+ );
+
+ return $this->response->response();
}
}
diff --git a/src/Controllers/Preferences/ManageController.php b/src/Controllers/Preferences/ManageController.php
index ff0b542723..3ec730d69a 100644
--- a/src/Controllers/Preferences/ManageController.php
+++ b/src/Controllers/Preferences/ManageController.php
@@ -221,7 +221,11 @@ final readonly class ManageController implements InvocableController
// reload config
$this->userPreferencesHandler->loadUserPreferences();
- return $this->userPreferences->redirect($returnUrl ?? '', $redirectParams);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect($returnUrl ?? '', $redirectParams),
+ );
+
+ return $this->response->response();
}
$error = $result;
@@ -231,7 +235,11 @@ final readonly class ManageController implements InvocableController
if ($result === true) {
$this->config->removeCookie('pma_lang');
- return $this->userPreferences->redirect('index.php?route=/preferences/manage');
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/manage'),
+ );
+
+ return $this->response->response();
}
return $this->response->response();
diff --git a/src/Controllers/Preferences/NavigationController.php b/src/Controllers/Preferences/NavigationController.php
index 98df87ec4d..703db6ea48 100644
--- a/src/Controllers/Preferences/NavigationController.php
+++ b/src/Controllers/Preferences/NavigationController.php
@@ -62,7 +62,11 @@ final readonly class NavigationController implements InvocableController
$this->userPreferencesHandler->loadUserPreferences();
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
- return $this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $hash);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/navigation', null, $hash),
+ );
+
+ return $this->response->response();
}
}
diff --git a/src/Controllers/Preferences/SqlController.php b/src/Controllers/Preferences/SqlController.php
index c9ec8a4db8..ec9bafac3e 100644
--- a/src/Controllers/Preferences/SqlController.php
+++ b/src/Controllers/Preferences/SqlController.php
@@ -62,7 +62,11 @@ final readonly class SqlController implements InvocableController
$this->userPreferencesHandler->loadUserPreferences();
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
- return $this->userPreferences->redirect('index.php?route=/preferences/sql', null, $hash);
+ $this->response->redirect(
+ $this->userPreferences->getUrlToRedirect('index.php?route=/preferences/sql', null, $hash),
+ );
+
+ return $this->response->response();
}
}
diff --git a/tests/unit/Config/UserPreferencesTest.php b/tests/unit/Config/UserPreferencesTest.php
index 711f406c54..4751d40e7b 100644
--- a/tests/unit/Config/UserPreferencesTest.php
+++ b/tests/unit/Config/UserPreferencesTest.php
@@ -14,14 +14,11 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Message;
-use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Clock\MockClock;
use PhpMyAdmin\Tests\Stubs\DummyResult;
-use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseRendererStub;
use PhpMyAdmin\Url;
-use PHPUnit\Framework\Attributes\BackupStaticProperties;
use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionProperty;
@@ -546,20 +543,11 @@ class UserPreferencesTest extends AbstractTestCase
);
}
- #[BackupStaticProperties(true)]
- public function testRedirect(): void
+ public function testGetUrlToRedirect(): void
{
- $responseStub = new ResponseRendererStub();
- (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub);
-
- Current::$lang = '';
- Current::$database = 'db';
- Current::$table = 'table';
-
- $config = Config::getInstance();
- $config->set('PmaAbsoluteUri', '');
-
- $dbi = DatabaseInterface::getInstance();
+ Current::$lang = 'en';
+ $config = new Config();
+ $dbi = $this->createDatabaseInterface();
$userPreferences = new UserPreferences(
$dbi,
new Relation($dbi, $config),
@@ -567,14 +555,10 @@ class UserPreferencesTest extends AbstractTestCase
$config,
new Clock(),
);
- $response = $userPreferences->redirect(
- 'file.html',
- ['a' => 'b'],
- 'h ash',
+ self::assertSame(
+ './file.html?a=b&saved=1&server=2&lang=en#h+ash',
+ $userPreferences->getUrlToRedirect('file.html', ['a' => 'b'], 'h ash'),
);
-
- self::assertSame(['/phpmyadmin/file.html?a=b&saved=1&server=2#h+ash'], $response->getHeader('Location'));
- self::assertSame(302, $response->getStatusCode());
}
/**