From 8089ab83cf8ed222ff478757cc5e31d5bafc72af Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 2 Jan 2023 13:00:57 +0100 Subject: [PATCH 1/2] add types for missing ones Signed-off-by: Simon L --- php/psalm-baseline.xml | 43 ------------------- php/public/index.php | 10 +++-- .../Controller/ConfigurationController.php | 2 +- php/src/Controller/DockerController.php | 16 +++---- php/src/Controller/LoginController.php | 6 +-- php/src/Twig/ClassExtension.php | 2 +- 6 files changed, 19 insertions(+), 60 deletions(-) diff --git a/php/psalm-baseline.xml b/php/psalm-baseline.xml index fcf5ebf0..3dc50575 100644 --- a/php/psalm-baseline.xml +++ b/php/psalm-baseline.xml @@ -1,46 +1,3 @@ - - - $args - $args - $args - $args - $request - $request - $request - $response - $response - $response - - - - - $args - - - - - $args - $args - $args - $args - $args - $args - $args - $args - - - - - $args - $args - $args - - - - - $object - - diff --git a/php/public/index.php b/php/public/index.php index aaf829c8..39c1465c 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -12,6 +12,8 @@ use Slim\Csrf\Guard; use Slim\Factory\AppFactory; use Slim\Views\Twig; use Slim\Views\TwigMiddleware; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; require __DIR__ . '/../vendor/autoload.php'; @@ -65,7 +67,7 @@ $app->post('/api/auth/logout', AIO\Controller\LoginController::class . ':Logout' $app->post('/api/configuration', \AIO\Controller\ConfigurationController::class . ':SetConfig'); // Views -$app->get('/containers', function ($request, $response, $args) use ($container) { +$app->get('/containers', function (Request $request, Response $response, mixed $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Data\ConfigurationManager $configurationManager */ $configurationManager = $container->get(\AIO\Data\ConfigurationManager::class); @@ -110,7 +112,7 @@ $app->get('/containers', function ($request, $response, $args) use ($container) 'additional_backup_directories' => $configurationManager->GetAdditionalBackupDirectoriesString(), ]); })->setName('profile'); -$app->get('/login', function ($request, $response, $args) use ($container) { +$app->get('/login', function (Request $request, Response $response, mixed $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Docker\DockerActionManager $dockerActionManger */ $dockerActionManger = $container->get(\AIO\Docker\DockerActionManager::class); @@ -118,7 +120,7 @@ $app->get('/login', function ($request, $response, $args) use ($container) { 'is_login_allowed' => $dockerActionManger->isLoginAllowed(), ]); }); -$app->get('/setup', function ($request, $response, $args) use ($container) { +$app->get('/setup', function (Request $request, Response $response, mixed $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Data\Setup $setup */ $setup = $container->get(\AIO\Data\Setup::class); @@ -140,7 +142,7 @@ $app->get('/setup', function ($request, $response, $args) use ($container) { }); // Auth Redirector -$app->get('/', function (\Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, $args) use ($container) { +$app->get('/', function (\Psr\Http\Message\RequestInterface $request, Response $response, mixed $args) use ($container) { $authManager = $container->get(\AIO\Auth\AuthManager::class); /** @var \AIO\Data\Setup $setup */ diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index a06cc6b9..95981a6a 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -19,7 +19,7 @@ class ConfigurationController $this->configurationManager = $configurationManager; } - public function SetConfig(Request $request, Response $response, $args) : Response { + public function SetConfig(Request $request, Response $response, mixed $args) : Response { try { if (isset($request->getParsedBody()['domain'])) { $domain = $request->getParsedBody()['domain'] ?? ''; diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 7cf15226..0ef76e4c 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -49,7 +49,7 @@ class DockerController $this->dockerActionManager->ConnectContainerToNetwork($container); } - public function GetLogs(Request $request, Response $response, $args) : Response + public function GetLogs(Request $request, Response $response, mixed $args) : Response { $id = $request->getQueryParams()['id']; if (str_starts_with($id, 'nextcloud-aio-')) { @@ -67,7 +67,7 @@ class DockerController ->withHeader('Content-Disposition', 'inline'); } - public function StartBackupContainerBackup(Request $request, Response $response, $args) : Response { + public function StartBackupContainerBackup(Request $request, Response $response, mixed $args) : Response { $this->startBackup(); return $response->withStatus(201)->withHeader('Location', '/'); } @@ -84,7 +84,7 @@ class DockerController $this->PerformRecursiveContainerStart($id); } - public function StartBackupContainerCheck(Request $request, Response $response, $args) : Response { + public function StartBackupContainerCheck(Request $request, Response $response, mixed $args) : Response { $this->checkBackup(); return $response->withStatus(201)->withHeader('Location', '/'); } @@ -98,7 +98,7 @@ class DockerController $this->PerformRecursiveContainerStart($id); } - public function StartBackupContainerRestore(Request $request, Response $response, $args) : Response { + public function StartBackupContainerRestore(Request $request, Response $response, mixed $args) : Response { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'restore'; $config['selected-restore-time'] = $request->getParsedBody()['selected_restore_time'] ?? ''; @@ -113,7 +113,7 @@ class DockerController return $response->withStatus(201)->withHeader('Location', '/'); } - public function StartBackupContainerTest(Request $request, Response $response, $args) : Response { + public function StartBackupContainerTest(Request $request, Response $response, mixed $args) : Response { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'test'; $config['instance_restore_attempt'] = 0; @@ -128,7 +128,7 @@ class DockerController return $response->withStatus(201)->withHeader('Location', '/'); } - public function StartContainer(Request $request, Response $response, $args) : Response + public function StartContainer(Request $request, Response $response, mixed $args) : Response { $uri = $request->getUri(); $host = $uri->getHost(); @@ -165,7 +165,7 @@ class DockerController $this->PerformRecursiveContainerStart($id, $pullContainer); } - public function StartWatchtowerContainer(Request $request, Response $response, $args) : Response { + public function StartWatchtowerContainer(Request $request, Response $response, mixed $args) : Response { $this->startWatchtower(); return $response->withStatus(201)->withHeader('Location', '/'); } @@ -188,7 +188,7 @@ class DockerController $this->dockerActionManager->StopContainer($container); } - public function StopContainer(Request $request, Response $response, $args) : Response + public function StopContainer(Request $request, Response $response, mixed $args) : Response { $id = self::TOP_CONTAINER; $this->PerformRecursiveContainerStop($id); diff --git a/php/src/Controller/LoginController.php b/php/src/Controller/LoginController.php index bd7cb0b5..d37b47a8 100644 --- a/php/src/Controller/LoginController.php +++ b/php/src/Controller/LoginController.php @@ -19,7 +19,7 @@ class LoginController $this->dockerActionManager = $dockerActionManager; } - public function TryLogin(Request $request, Response $response, $args) : Response { + public function TryLogin(Request $request, Response $response, mixed $args) : Response { if (!$this->dockerActionManager->isLoginAllowed()) { return $response->withHeader('Location', '/')->withStatus(302); } @@ -32,7 +32,7 @@ class LoginController return $response->withHeader('Location', '/')->withStatus(302); } - public function GetTryLogin(Request $request, Response $response, $args) : Response { + public function GetTryLogin(Request $request, Response $response, mixed $args) : Response { $token = $request->getQueryParams()['token'] ?? ''; if($this->authManager->CheckToken($token)) { $this->authManager->SetAuthState(true); @@ -42,7 +42,7 @@ class LoginController return $response->withHeader('Location', '/')->withStatus(302); } - public function Logout(Request $request, Response $response, $args) : Response + public function Logout(Request $request, Response $response, mixed $args) : Response { $this->authManager->SetAuthState(false); return $response diff --git a/php/src/Twig/ClassExtension.php b/php/src/Twig/ClassExtension.php index 9204aee1..ff5ffe44 100644 --- a/php/src/Twig/ClassExtension.php +++ b/php/src/Twig/ClassExtension.php @@ -14,7 +14,7 @@ class ClassExtension extends TwigExtension ); } - public function getClassName($object) : ?string + public function getClassName(mixed $object) : ?string { if (!is_object($object)) { return null; From f272979c43d9e8d7d959d8475a8445e940c84659 Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 2 Jan 2023 15:46:58 +0100 Subject: [PATCH 2/2] address review by making $args an array Signed-off-by: Simon L --- php/public/index.php | 8 ++++---- php/src/Controller/ConfigurationController.php | 2 +- php/src/Controller/DockerController.php | 16 ++++++++-------- php/src/Controller/LoginController.php | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/php/public/index.php b/php/public/index.php index 39c1465c..b8f48ce9 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -67,7 +67,7 @@ $app->post('/api/auth/logout', AIO\Controller\LoginController::class . ':Logout' $app->post('/api/configuration', \AIO\Controller\ConfigurationController::class . ':SetConfig'); // Views -$app->get('/containers', function (Request $request, Response $response, mixed $args) use ($container) { +$app->get('/containers', function (Request $request, Response $response, array $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Data\ConfigurationManager $configurationManager */ $configurationManager = $container->get(\AIO\Data\ConfigurationManager::class); @@ -112,7 +112,7 @@ $app->get('/containers', function (Request $request, Response $response, mixed $ 'additional_backup_directories' => $configurationManager->GetAdditionalBackupDirectoriesString(), ]); })->setName('profile'); -$app->get('/login', function (Request $request, Response $response, mixed $args) use ($container) { +$app->get('/login', function (Request $request, Response $response, array $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Docker\DockerActionManager $dockerActionManger */ $dockerActionManger = $container->get(\AIO\Docker\DockerActionManager::class); @@ -120,7 +120,7 @@ $app->get('/login', function (Request $request, Response $response, mixed $args) 'is_login_allowed' => $dockerActionManger->isLoginAllowed(), ]); }); -$app->get('/setup', function (Request $request, Response $response, mixed $args) use ($container) { +$app->get('/setup', function (Request $request, Response $response, array $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Data\Setup $setup */ $setup = $container->get(\AIO\Data\Setup::class); @@ -142,7 +142,7 @@ $app->get('/setup', function (Request $request, Response $response, mixed $args) }); // Auth Redirector -$app->get('/', function (\Psr\Http\Message\RequestInterface $request, Response $response, mixed $args) use ($container) { +$app->get('/', function (\Psr\Http\Message\RequestInterface $request, Response $response, array $args) use ($container) { $authManager = $container->get(\AIO\Auth\AuthManager::class); /** @var \AIO\Data\Setup $setup */ diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index 95981a6a..561cec8c 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -19,7 +19,7 @@ class ConfigurationController $this->configurationManager = $configurationManager; } - public function SetConfig(Request $request, Response $response, mixed $args) : Response { + public function SetConfig(Request $request, Response $response, array $args) : Response { try { if (isset($request->getParsedBody()['domain'])) { $domain = $request->getParsedBody()['domain'] ?? ''; diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 0ef76e4c..979edbc8 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -49,7 +49,7 @@ class DockerController $this->dockerActionManager->ConnectContainerToNetwork($container); } - public function GetLogs(Request $request, Response $response, mixed $args) : Response + public function GetLogs(Request $request, Response $response, array $args) : Response { $id = $request->getQueryParams()['id']; if (str_starts_with($id, 'nextcloud-aio-')) { @@ -67,7 +67,7 @@ class DockerController ->withHeader('Content-Disposition', 'inline'); } - public function StartBackupContainerBackup(Request $request, Response $response, mixed $args) : Response { + public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response { $this->startBackup(); return $response->withStatus(201)->withHeader('Location', '/'); } @@ -84,7 +84,7 @@ class DockerController $this->PerformRecursiveContainerStart($id); } - public function StartBackupContainerCheck(Request $request, Response $response, mixed $args) : Response { + public function StartBackupContainerCheck(Request $request, Response $response, array $args) : Response { $this->checkBackup(); return $response->withStatus(201)->withHeader('Location', '/'); } @@ -98,7 +98,7 @@ class DockerController $this->PerformRecursiveContainerStart($id); } - public function StartBackupContainerRestore(Request $request, Response $response, mixed $args) : Response { + public function StartBackupContainerRestore(Request $request, Response $response, array $args) : Response { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'restore'; $config['selected-restore-time'] = $request->getParsedBody()['selected_restore_time'] ?? ''; @@ -113,7 +113,7 @@ class DockerController return $response->withStatus(201)->withHeader('Location', '/'); } - public function StartBackupContainerTest(Request $request, Response $response, mixed $args) : Response { + public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'test'; $config['instance_restore_attempt'] = 0; @@ -128,7 +128,7 @@ class DockerController return $response->withStatus(201)->withHeader('Location', '/'); } - public function StartContainer(Request $request, Response $response, mixed $args) : Response + public function StartContainer(Request $request, Response $response, array $args) : Response { $uri = $request->getUri(); $host = $uri->getHost(); @@ -165,7 +165,7 @@ class DockerController $this->PerformRecursiveContainerStart($id, $pullContainer); } - public function StartWatchtowerContainer(Request $request, Response $response, mixed $args) : Response { + public function StartWatchtowerContainer(Request $request, Response $response, array $args) : Response { $this->startWatchtower(); return $response->withStatus(201)->withHeader('Location', '/'); } @@ -188,7 +188,7 @@ class DockerController $this->dockerActionManager->StopContainer($container); } - public function StopContainer(Request $request, Response $response, mixed $args) : Response + public function StopContainer(Request $request, Response $response, array $args) : Response { $id = self::TOP_CONTAINER; $this->PerformRecursiveContainerStop($id); diff --git a/php/src/Controller/LoginController.php b/php/src/Controller/LoginController.php index d37b47a8..81b1ab84 100644 --- a/php/src/Controller/LoginController.php +++ b/php/src/Controller/LoginController.php @@ -19,7 +19,7 @@ class LoginController $this->dockerActionManager = $dockerActionManager; } - public function TryLogin(Request $request, Response $response, mixed $args) : Response { + public function TryLogin(Request $request, Response $response, array $args) : Response { if (!$this->dockerActionManager->isLoginAllowed()) { return $response->withHeader('Location', '/')->withStatus(302); } @@ -32,7 +32,7 @@ class LoginController return $response->withHeader('Location', '/')->withStatus(302); } - public function GetTryLogin(Request $request, Response $response, mixed $args) : Response { + public function GetTryLogin(Request $request, Response $response, array $args) : Response { $token = $request->getQueryParams()['token'] ?? ''; if($this->authManager->CheckToken($token)) { $this->authManager->SetAuthState(true); @@ -42,7 +42,7 @@ class LoginController return $response->withHeader('Location', '/')->withStatus(302); } - public function Logout(Request $request, Response $response, mixed $args) : Response + public function Logout(Request $request, Response $response, array $args) : Response { $this->authManager->SetAuthState(false); return $response