diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f857319b5b..a27ee53311 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3780,6 +3780,11 @@ parameters: 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 diff --git a/src/Controllers/Setup/MainController.php b/src/Controllers/Setup/MainController.php index 17e47b44f1..3454835106 100644 --- a/src/Controllers/Setup/MainController.php +++ b/src/Controllers/Setup/MainController.php @@ -64,9 +64,8 @@ final class MainController implements InvocableController } if ($page === 'servers') { - $controller = new ServersController($GLOBALS['ConfigFile'], $this->template); if ($request->getQueryParam('mode') === 'remove' && $request->isPost()) { - $controller->destroy($request); + (new ServerDestroyController($GLOBALS['ConfigFile'], $this->template))($request); $response = $response->withStatus(StatusCodeInterface::STATUS_FOUND); return $response->withHeader( @@ -75,7 +74,7 @@ final class MainController implements InvocableController ); } - return $response->write($controller->index($request)); + return $response->write((new ServersController($GLOBALS['ConfigFile'], $this->template))($request)); } return $response->write((new HomeController($GLOBALS['ConfigFile'], $this->template))($request)); diff --git a/src/Controllers/Setup/ServerDestroyController.php b/src/Controllers/Setup/ServerDestroyController.php new file mode 100644 index 0000000000..8b29faf388 --- /dev/null +++ b/src/Controllers/Setup/ServerDestroyController.php @@ -0,0 +1,35 @@ +getIdParam($request->getQueryParam('id')); + $hasServer = $id >= 1 && $this->config->get('Servers/' . $id) !== null; + if (! $hasServer) { + return; + } + + $this->config->removeServer($id); + } + + /** @psalm-return int<0, max> */ + private function getIdParam(mixed $idParam): int + { + if (! is_numeric($idParam)) { + return 0; + } + + $id = (int) $idParam; + + return $id >= 1 ? $id : 0; + } +} diff --git a/src/Controllers/Setup/ServersController.php b/src/Controllers/Setup/ServersController.php index a47ff27e91..e144c61983 100644 --- a/src/Controllers/Setup/ServersController.php +++ b/src/Controllers/Setup/ServersController.php @@ -16,7 +16,7 @@ use function ob_start; class ServersController extends AbstractController { - public function index(ServerRequest $request): string + public function __invoke(ServerRequest $request): string { $id = $this->getIdParam($request->getQueryParam('id')); $mode = $this->getModeParam($request->getQueryParam('mode')); @@ -44,17 +44,6 @@ class ServersController extends AbstractController ]); } - public function destroy(ServerRequest $request): void - { - $id = $this->getIdParam($request->getQueryParam('id')); - $hasServer = $id >= 1 && $this->config->get('Servers/' . $id) !== null; - if (! $hasServer) { - return; - } - - $this->config->removeServer($id); - } - private function getFormSetParam(mixed $formSetParam): string { return is_string($formSetParam) ? $formSetParam : '';