From 0e361b9de181742b25f56dce5c197e247a889e44 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Dec 2024 18:00:08 +0700 Subject: [PATCH 1/7] refactor: enable code quality level 34 for rector --- rector.php | 4 +--- system/CLI/Commands.php | 4 ++-- system/CodeIgniter.php | 6 ++++-- system/Commands/Database/MigrateRollback.php | 3 ++- system/Database/BaseBuilder.php | 5 +++-- system/Filters/CSRF.php | 5 +++-- system/Filters/Cors.php | 10 +++++----- system/Filters/ForceHTTPS.php | 5 +++-- system/Filters/PageCache.php | 3 ++- system/Images/Handlers/BaseHandler.php | 1 + system/Language/Language.php | 3 ++- system/Security/CheckPhpIni.php | 4 ++-- system/Session/Session.php | 8 ++++---- system/Test/CIUnitTestCase.php | 3 ++- 14 files changed, 36 insertions(+), 28 deletions(-) diff --git a/rector.php b/rector.php index e7c98746eb86..e2df4f9b63e5 100644 --- a/rector.php +++ b/rector.php @@ -19,7 +19,6 @@ use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; -use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector; use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; @@ -186,7 +185,6 @@ ChangeIfElseValueAssignToEarlyReturnRector::class, InlineIfToExplicitIfRector::class, PreparedValueToEarlyReturnRector::class, - ShortenElseIfRector::class, UnusedForeachValueToArrayKeysRector::class, ChangeArrayPushToArrayAssignRector::class, RemoveErrorSuppressInTryCatchStmtsRector::class, @@ -210,4 +208,4 @@ // keep '\\' prefix string on string '\Foo\Bar' StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true, ]) - ->withCodeQualityLevel(31); + ->withCodeQualityLevel(34); diff --git a/system/CLI/Commands.php b/system/CLI/Commands.php index 2115714106bc..d8509b0c0722 100644 --- a/system/CLI/Commands.php +++ b/system/CLI/Commands.php @@ -52,12 +52,12 @@ public function __construct($logger = null) /** * Runs a command given * - * @return int|void Exit code + * @return int|null Exit code */ public function run(string $command, array $params) { if (! $this->verifyCommand($command, $this->commands)) { - return; + return null; } // The file would have already been loaded during the diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 8ff5d2ae5b9b..d44a2025428a 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -318,7 +318,7 @@ private function configureKint(): void * * @param bool $returnResponse Used for testing purposes only. * - * @return ResponseInterface|void + * @return ResponseInterface|null */ public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false) { @@ -379,6 +379,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon } $this->sendResponse(); + return null; } /** @@ -863,7 +864,7 @@ protected function determinePath() * controller method and make the script go. If it's not able to, will * show the appropriate Page Not Found error. * - * @return ResponseInterface|string|void + * @return ResponseInterface|string|null */ protected function startController() { @@ -889,6 +890,7 @@ protected function startController() ) { throw PageNotFoundException::forControllerNotFound($this->controller, $this->method); } + return null; } /** diff --git a/system/Commands/Database/MigrateRollback.php b/system/Commands/Database/MigrateRollback.php index e1c788e7702e..fa77c15aa4ab 100644 --- a/system/Commands/Database/MigrateRollback.php +++ b/system/Commands/Database/MigrateRollback.php @@ -74,7 +74,7 @@ public function run(array $params) $force = array_key_exists('f', $params) || CLI::getOption('f'); if (! $force && CLI::prompt(lang('Migrations.rollBackConfirm'), ['y', 'n']) === 'n') { - return; + return null; } // @codeCoverageIgnoreEnd } @@ -115,5 +115,6 @@ public function run(array $params) $this->showError($e); // @codeCoverageIgnoreEnd } + return null; } } diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index ad1967120af5..c4a29c04eb90 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -3019,7 +3019,7 @@ protected function _delete(string $table): string * * @param array|string $table The table to inspect * - * @return string|void + * @return string|null */ protected function trackAliases($table) { @@ -3028,7 +3028,7 @@ protected function trackAliases($table) $this->trackAliases($t); } - return; + return null; } // Does the string contain a comma? If so, we need to separate @@ -3048,6 +3048,7 @@ protected function trackAliases($table) // Store the alias, if it doesn't already exist $this->db->addTableAlias($alias); } + return null; } /** diff --git a/system/Filters/CSRF.php b/system/Filters/CSRF.php index beb15f62b03a..69a5d9a621d2 100644 --- a/system/Filters/CSRF.php +++ b/system/Filters/CSRF.php @@ -35,14 +35,14 @@ class CSRF implements FilterInterface * * @param list|null $arguments * - * @return RedirectResponse|void + * @return RedirectResponse|null * * @throws SecurityException */ public function before(RequestInterface $request, $arguments = null) { if (! $request instanceof IncomingRequest) { - return; + return null; } /** @var Security $security */ @@ -57,6 +57,7 @@ public function before(RequestInterface $request, $arguments = null) throw $e; } + return null; } /** diff --git a/system/Filters/Cors.php b/system/Filters/Cors.php index 93ca551b42f2..2c2d805c2d74 100644 --- a/system/Filters/Cors.php +++ b/system/Filters/Cors.php @@ -48,18 +48,18 @@ public function __construct(array $config = []) /** * @param list|null $arguments * - * @return ResponseInterface|string|void + * @return ResponseInterface|string|null */ public function before(RequestInterface $request, $arguments = null) { if (! $request instanceof IncomingRequest) { - return; + return null; } $this->createCorsService($arguments); if (! $this->cors->isPreflightRequest($request)) { - return; + return null; } /** @var ResponseInterface $response */ @@ -88,12 +88,12 @@ private function createCorsService(?array $arguments): void /** * @param list|null $arguments * - * @return ResponseInterface|void + * @return ResponseInterface|null */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { if (! $request instanceof IncomingRequest) { - return; + return null; } $this->createCorsService($arguments); diff --git a/system/Filters/ForceHTTPS.php b/system/Filters/ForceHTTPS.php index f415bd00e3b8..d7bf877242e3 100644 --- a/system/Filters/ForceHTTPS.php +++ b/system/Filters/ForceHTTPS.php @@ -32,14 +32,14 @@ class ForceHTTPS implements FilterInterface * * @param array|null $arguments * - * @return ResponseInterface|void + * @return ResponseInterface|null */ public function before(RequestInterface $request, $arguments = null) { $config = config(App::class); if ($config->forceGlobalSecureRequests !== true) { - return; + return null; } $response = service('response'); @@ -49,6 +49,7 @@ public function before(RequestInterface $request, $arguments = null) } catch (RedirectException $e) { return $e->getResponse(); } + return null; } /** diff --git a/system/Filters/PageCache.php b/system/Filters/PageCache.php index a3d3af832a65..cb29969bacc6 100644 --- a/system/Filters/PageCache.php +++ b/system/Filters/PageCache.php @@ -38,7 +38,7 @@ public function __construct() * * @param array|null $arguments * - * @return ResponseInterface|void + * @return ResponseInterface|null */ public function before(RequestInterface $request, $arguments = null) { @@ -51,6 +51,7 @@ public function before(RequestInterface $request, $arguments = null) if ($cachedResponse instanceof ResponseInterface) { return $cachedResponse; } + return null; } /** diff --git a/system/Images/Handlers/BaseHandler.php b/system/Images/Handlers/BaseHandler.php index a6607e04d160..8313efec3095 100644 --- a/system/Images/Handlers/BaseHandler.php +++ b/system/Images/Handlers/BaseHandler.php @@ -702,6 +702,7 @@ public function __call(string $name, array $args = []) if (method_exists($this->image(), $name)) { return $this->image()->{$name}(...$args); } + return null; } /** diff --git a/system/Language/Language.php b/system/Language/Language.php index 1ab2c5269195..ddb9a738912f 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -232,7 +232,7 @@ protected function formatMessage($message, array $args = []) * will return the file's contents, otherwise will merge with * the existing language lines. * - * @return array|void + * @return mixed[]|null */ protected function load(string $file, string $locale, bool $return = false) { @@ -265,6 +265,7 @@ protected function load(string $file, string $locale, bool $return = false) // Merge our string $this->language[$locale][$file] = $lang; + return null; } /** diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index 59cd587360d5..1293e1c1db87 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -27,7 +27,7 @@ class CheckPhpIni /** * @param bool $isCli Set false if you run via Web * - * @return string|void HTML string or void in CLI + * @return string|null HTML string or void in CLI */ public static function run(bool $isCli = true) { @@ -40,7 +40,7 @@ public static function run(bool $isCli = true) if ($isCli) { self::outputForCli($output, $thead, $tbody); - return; + return null; } // Web diff --git a/system/Session/Session.php b/system/Session/Session.php index 44f0841932d0..61dd2b6aff20 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -205,7 +205,7 @@ public function __construct(SessionHandlerInterface $driver, SessionConfig $conf /** * Initialize the session container and starts up the session. * - * @return $this|void + * @return $this|null */ public function start() { @@ -213,20 +213,20 @@ public function start() // @codeCoverageIgnoreStart $this->logger->debug('Session: Initialization under CLI aborted.'); - return; + return null; // @codeCoverageIgnoreEnd } if ((bool) ini_get('session.auto_start')) { $this->logger->error('Session: session.auto_start is enabled in php.ini. Aborting.'); - return; + return null; } if (session_status() === PHP_SESSION_ACTIVE) { $this->logger->warning('Session: Sessions is enabled, and one exists. Please don\'t $session->start();'); - return; + return null; } $this->configure(); diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index 62c0fff83844..676b3dfb8333 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -461,7 +461,7 @@ public function assertCloseEnough(int $expected, $actual, string $message = '', * @param mixed $expected * @param mixed $actual * - * @return bool|void + * @return bool|null * * @throws Exception */ @@ -482,6 +482,7 @@ public function assertCloseEnoughString($expected, $actual, string $message = '' } catch (Exception) { return false; } + return null; } // -------------------------------------------------------------------- From 8702e47b4bc5d7ab1a6ebdb52950558885ea102c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Dec 2024 18:02:40 +0700 Subject: [PATCH 2/7] refactor: run cs fix --- system/CodeIgniter.php | 2 ++ system/Commands/Database/MigrateRollback.php | 1 + system/Database/BaseBuilder.php | 1 + system/Filters/CSRF.php | 1 + system/Filters/ForceHTTPS.php | 1 + system/Filters/PageCache.php | 1 + system/Images/Handlers/BaseHandler.php | 1 + system/Language/Language.php | 3 ++- system/Test/CIUnitTestCase.php | 1 + 9 files changed, 11 insertions(+), 1 deletion(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index d44a2025428a..ef4db424a5f0 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -379,6 +379,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon } $this->sendResponse(); + return null; } @@ -890,6 +891,7 @@ protected function startController() ) { throw PageNotFoundException::forControllerNotFound($this->controller, $this->method); } + return null; } diff --git a/system/Commands/Database/MigrateRollback.php b/system/Commands/Database/MigrateRollback.php index fa77c15aa4ab..cb6cbe3a7adb 100644 --- a/system/Commands/Database/MigrateRollback.php +++ b/system/Commands/Database/MigrateRollback.php @@ -115,6 +115,7 @@ public function run(array $params) $this->showError($e); // @codeCoverageIgnoreEnd } + return null; } } diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index c4a29c04eb90..73cc2677274f 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -3048,6 +3048,7 @@ protected function trackAliases($table) // Store the alias, if it doesn't already exist $this->db->addTableAlias($alias); } + return null; } diff --git a/system/Filters/CSRF.php b/system/Filters/CSRF.php index 69a5d9a621d2..6d90d6aee817 100644 --- a/system/Filters/CSRF.php +++ b/system/Filters/CSRF.php @@ -57,6 +57,7 @@ public function before(RequestInterface $request, $arguments = null) throw $e; } + return null; } diff --git a/system/Filters/ForceHTTPS.php b/system/Filters/ForceHTTPS.php index d7bf877242e3..1a5bdc84349d 100644 --- a/system/Filters/ForceHTTPS.php +++ b/system/Filters/ForceHTTPS.php @@ -49,6 +49,7 @@ public function before(RequestInterface $request, $arguments = null) } catch (RedirectException $e) { return $e->getResponse(); } + return null; } diff --git a/system/Filters/PageCache.php b/system/Filters/PageCache.php index cb29969bacc6..d4fb6ab24662 100644 --- a/system/Filters/PageCache.php +++ b/system/Filters/PageCache.php @@ -51,6 +51,7 @@ public function before(RequestInterface $request, $arguments = null) if ($cachedResponse instanceof ResponseInterface) { return $cachedResponse; } + return null; } diff --git a/system/Images/Handlers/BaseHandler.php b/system/Images/Handlers/BaseHandler.php index 8313efec3095..033c4e6beda7 100644 --- a/system/Images/Handlers/BaseHandler.php +++ b/system/Images/Handlers/BaseHandler.php @@ -702,6 +702,7 @@ public function __call(string $name, array $args = []) if (method_exists($this->image(), $name)) { return $this->image()->{$name}(...$args); } + return null; } diff --git a/system/Language/Language.php b/system/Language/Language.php index ddb9a738912f..c0591328f5ef 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -232,7 +232,7 @@ protected function formatMessage($message, array $args = []) * will return the file's contents, otherwise will merge with * the existing language lines. * - * @return mixed[]|null + * @return list|null */ protected function load(string $file, string $locale, bool $return = false) { @@ -265,6 +265,7 @@ protected function load(string $file, string $locale, bool $return = false) // Merge our string $this->language[$locale][$file] = $lang; + return null; } diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index 676b3dfb8333..f237ab862a64 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -482,6 +482,7 @@ public function assertCloseEnoughString($expected, $actual, string $message = '' } catch (Exception) { return false; } + return null; } From 0ab9cfc89b72dcbe37536a4051224f9f54c62635 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Dec 2024 18:54:09 +0700 Subject: [PATCH 3/7] refactor: fix phpstan and regenerate baseline --- system/Filters/CSRF.php | 3 +-- system/Filters/DebugToolbar.php | 3 +++ system/Filters/FilterInterface.php | 4 ++-- system/Filters/ForceHTTPS.php | 3 +-- system/Filters/Honeypot.php | 6 +++++- system/Filters/InvalidChars.php | 9 ++++----- system/Filters/PageCache.php | 5 +++-- system/Filters/PerformanceMetrics.php | 7 +++++-- system/Filters/SecureHeaders.php | 7 +++---- tests/_support/Filters/Customfilter.php | 3 ++- tests/_support/Filters/RedirectFilter.php | 3 ++- tests/system/Filters/fixtures/GoogleCurious.php | 3 ++- tests/system/Filters/fixtures/GoogleEmpty.php | 3 ++- tests/system/Filters/fixtures/GoogleYou.php | 3 ++- tests/system/Filters/fixtures/Multiple1.php | 3 ++- tests/system/Filters/fixtures/Multiple2.php | 3 ++- 16 files changed, 41 insertions(+), 27 deletions(-) diff --git a/system/Filters/CSRF.php b/system/Filters/CSRF.php index 6d90d6aee817..ea9a9939f2de 100644 --- a/system/Filters/CSRF.php +++ b/system/Filters/CSRF.php @@ -65,10 +65,9 @@ public function before(RequestInterface $request, $arguments = null) * We don't have anything to do here. * * @param list|null $arguments - * - * @return void */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/system/Filters/DebugToolbar.php b/system/Filters/DebugToolbar.php index 9f864ee572c5..9e888ead35bb 100644 --- a/system/Filters/DebugToolbar.php +++ b/system/Filters/DebugToolbar.php @@ -30,6 +30,7 @@ class DebugToolbar implements FilterInterface */ public function before(RequestInterface $request, $arguments = null) { + return null; } /** @@ -41,5 +42,7 @@ public function before(RequestInterface $request, $arguments = null) public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { service('toolbar')->prepare($request, $response); + + return $response; } } diff --git a/system/Filters/FilterInterface.php b/system/Filters/FilterInterface.php index 0353fb2ab9d0..6df33e912b87 100644 --- a/system/Filters/FilterInterface.php +++ b/system/Filters/FilterInterface.php @@ -33,7 +33,7 @@ interface FilterInterface * * @param list|null $arguments * - * @return RequestInterface|ResponseInterface|string|void + * @return RequestInterface|ResponseInterface|string|null */ public function before(RequestInterface $request, $arguments = null); @@ -45,7 +45,7 @@ public function before(RequestInterface $request, $arguments = null); * * @param list|null $arguments * - * @return ResponseInterface|void + * @return ResponseInterface|null */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null); } diff --git a/system/Filters/ForceHTTPS.php b/system/Filters/ForceHTTPS.php index 1a5bdc84349d..aa9cb3716d08 100644 --- a/system/Filters/ForceHTTPS.php +++ b/system/Filters/ForceHTTPS.php @@ -57,10 +57,9 @@ public function before(RequestInterface $request, $arguments = null) * We don't have anything to do here. * * @param array|null $arguments - * - * @return void */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/system/Filters/Honeypot.php b/system/Filters/Honeypot.php index cdff293aacb4..0a2745963595 100644 --- a/system/Filters/Honeypot.php +++ b/system/Filters/Honeypot.php @@ -36,12 +36,14 @@ class Honeypot implements FilterInterface public function before(RequestInterface $request, $arguments = null) { if (! $request instanceof IncomingRequest) { - return; + return null; } if (service('honeypot')->hasContent($request)) { throw HoneypotException::isBot(); } + + return null; } /** @@ -52,5 +54,7 @@ public function before(RequestInterface $request, $arguments = null) public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { service('honeypot')->attachHoneypot($response); + + return $response; } } diff --git a/system/Filters/InvalidChars.php b/system/Filters/InvalidChars.php index 542b12d7ffbe..1cd775153c0e 100644 --- a/system/Filters/InvalidChars.php +++ b/system/Filters/InvalidChars.php @@ -48,13 +48,11 @@ class InvalidChars implements FilterInterface * Check invalid characters. * * @param list|null $arguments - * - * @return void */ public function before(RequestInterface $request, $arguments = null) { if (! $request instanceof IncomingRequest) { - return; + return null; } $data = [ @@ -69,17 +67,18 @@ public function before(RequestInterface $request, $arguments = null) $this->checkEncoding($values); $this->checkControl($values); } + + return null; } /** * We don't have anything to do here. * * @param list|null $arguments - * - * @return void */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } /** diff --git a/system/Filters/PageCache.php b/system/Filters/PageCache.php index d4fb6ab24662..76a3faaaf7e1 100644 --- a/system/Filters/PageCache.php +++ b/system/Filters/PageCache.php @@ -59,8 +59,6 @@ public function before(RequestInterface $request, $arguments = null) * Cache the page. * * @param array|null $arguments - * - * @return void */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { @@ -74,6 +72,9 @@ public function after(RequestInterface $request, ResponseInterface $response, $a // so that we can have live speed updates along the way. // Must be run after filters to preserve the Response headers. $this->pageCache->make($request, $response); + return $response; } + + return null; } } diff --git a/system/Filters/PerformanceMetrics.php b/system/Filters/PerformanceMetrics.php index f2371c7a8d6d..0a9db2078500 100644 --- a/system/Filters/PerformanceMetrics.php +++ b/system/Filters/PerformanceMetrics.php @@ -28,14 +28,13 @@ class PerformanceMetrics implements FilterInterface */ public function before(RequestInterface $request, $arguments = null) { + return null; } /** * Replaces the performance metrics. * * @param array|null $arguments - * - * @return void */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { @@ -57,6 +56,10 @@ public function after(RequestInterface $request, ResponseInterface $response, $a ); $response->setBody($output); + + return $response; } + + return null; } } diff --git a/system/Filters/SecureHeaders.php b/system/Filters/SecureHeaders.php index b8bd6e05f8eb..42e5842384db 100644 --- a/system/Filters/SecureHeaders.php +++ b/system/Filters/SecureHeaders.php @@ -52,24 +52,23 @@ class SecureHeaders implements FilterInterface * We don't have anything to do here. * * @param list|null $arguments - * - * @return void */ public function before(RequestInterface $request, $arguments = null) { + return null; } /** * Add security headers. * * @param list|null $arguments - * - * @return void */ public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { foreach ($this->headers as $header => $value) { $response->setHeader($header, $value); } + + return $response; } } diff --git a/tests/_support/Filters/Customfilter.php b/tests/_support/Filters/Customfilter.php index ac8bce0f0271..7cfb89f60d48 100644 --- a/tests/_support/Filters/Customfilter.php +++ b/tests/_support/Filters/Customfilter.php @@ -26,7 +26,8 @@ public function before(RequestInterface $request, $arguments = null) return $request; } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/tests/_support/Filters/RedirectFilter.php b/tests/_support/Filters/RedirectFilter.php index 8ab62eb665ca..b2e9289d6b6b 100644 --- a/tests/_support/Filters/RedirectFilter.php +++ b/tests/_support/Filters/RedirectFilter.php @@ -24,7 +24,8 @@ public function before(RequestInterface $request, $arguments = null) return redirect()->to('login'); } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/tests/system/Filters/fixtures/GoogleCurious.php b/tests/system/Filters/fixtures/GoogleCurious.php index f00bc065f1d7..6a6871fcc8d4 100644 --- a/tests/system/Filters/fixtures/GoogleCurious.php +++ b/tests/system/Filters/fixtures/GoogleCurious.php @@ -24,7 +24,8 @@ public function before(RequestInterface $request, $arguments = null) return 'This is curious'; } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/tests/system/Filters/fixtures/GoogleEmpty.php b/tests/system/Filters/fixtures/GoogleEmpty.php index 6b0003e8de16..9de00d28f514 100644 --- a/tests/system/Filters/fixtures/GoogleEmpty.php +++ b/tests/system/Filters/fixtures/GoogleEmpty.php @@ -24,7 +24,8 @@ public function before(RequestInterface $request, $arguments = null) return ''; } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/tests/system/Filters/fixtures/GoogleYou.php b/tests/system/Filters/fixtures/GoogleYou.php index 7d2913866b30..5911940b2954 100644 --- a/tests/system/Filters/fixtures/GoogleYou.php +++ b/tests/system/Filters/fixtures/GoogleYou.php @@ -27,7 +27,8 @@ public function before(RequestInterface $request, $arguments = null) return $response; } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/tests/system/Filters/fixtures/Multiple1.php b/tests/system/Filters/fixtures/Multiple1.php index e9f4f49a10ab..6d2cee231808 100644 --- a/tests/system/Filters/fixtures/Multiple1.php +++ b/tests/system/Filters/fixtures/Multiple1.php @@ -26,7 +26,8 @@ public function before(RequestInterface $request, $arguments = null) return $request; } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } diff --git a/tests/system/Filters/fixtures/Multiple2.php b/tests/system/Filters/fixtures/Multiple2.php index 5520ce549930..d86f8fa79399 100644 --- a/tests/system/Filters/fixtures/Multiple2.php +++ b/tests/system/Filters/fixtures/Multiple2.php @@ -26,7 +26,8 @@ public function before(RequestInterface $request, $arguments = null) return $request; } - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { + return null; } } From 37d6980a352e75353837f00ae47989e4fab7a945 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Dec 2024 18:56:35 +0700 Subject: [PATCH 4/7] refactor: cs fix --- system/Filters/PageCache.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/Filters/PageCache.php b/system/Filters/PageCache.php index 76a3faaaf7e1..b0013c81ce37 100644 --- a/system/Filters/PageCache.php +++ b/system/Filters/PageCache.php @@ -72,6 +72,7 @@ public function after(RequestInterface $request, ResponseInterface $response, $a // so that we can have live speed updates along the way. // Must be run after filters to preserve the Response headers. $this->pageCache->make($request, $response); + return $response; } From 4f64e5414849605f78bb94610977904b79c3b1b4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Dec 2024 20:37:47 +0700 Subject: [PATCH 5/7] refactor: Cors: before never returns string --- system/Filters/Cors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Filters/Cors.php b/system/Filters/Cors.php index 2c2d805c2d74..9a9bbb208152 100644 --- a/system/Filters/Cors.php +++ b/system/Filters/Cors.php @@ -48,7 +48,7 @@ public function __construct(array $config = []) /** * @param list|null $arguments * - * @return ResponseInterface|string|null + * @return ResponseInterface|null */ public function before(RequestInterface $request, $arguments = null) { From e8178ebc498cc969a4f125be3c1c92dc9128b2b1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 10 Dec 2024 21:13:07 +0700 Subject: [PATCH 6/7] refactor: return EXIT_ERROR on check verify command --- system/CLI/Commands.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/CLI/Commands.php b/system/CLI/Commands.php index d8509b0c0722..732cb370382d 100644 --- a/system/CLI/Commands.php +++ b/system/CLI/Commands.php @@ -52,12 +52,12 @@ public function __construct($logger = null) /** * Runs a command given * - * @return int|null Exit code + * @return int Exit code */ public function run(string $command, array $params) { if (! $this->verifyCommand($command, $this->commands)) { - return null; + return EXIT_ERROR; } // The file would have already been loaded during the From 88862ad8fae0b7c3eef5dc6ecea11cbaeef59e76 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 11 Dec 2024 14:51:22 +0700 Subject: [PATCH 7/7] refactor: returns null on DebugToolbar and HoneyPot --- system/Filters/DebugToolbar.php | 2 +- system/Filters/Honeypot.php | 2 +- utils/phpstan-baseline/missingType.iterableValue.neon | 7 +------ utils/phpstan-baseline/return.missing.neon | 7 +------ 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/system/Filters/DebugToolbar.php b/system/Filters/DebugToolbar.php index 9e888ead35bb..7199b85f9d62 100644 --- a/system/Filters/DebugToolbar.php +++ b/system/Filters/DebugToolbar.php @@ -43,6 +43,6 @@ public function after(RequestInterface $request, ResponseInterface $response, $a { service('toolbar')->prepare($request, $response); - return $response; + return null; } } diff --git a/system/Filters/Honeypot.php b/system/Filters/Honeypot.php index 0a2745963595..4b24691ef905 100644 --- a/system/Filters/Honeypot.php +++ b/system/Filters/Honeypot.php @@ -55,6 +55,6 @@ public function after(RequestInterface $request, ResponseInterface $response, $a { service('honeypot')->attachHoneypot($response); - return $response; + return null; } } diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index d2c0fdf7c22c..60bb03868b8a 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1673 errors +# total 1672 errors parameters: ignoreErrors: @@ -4707,11 +4707,6 @@ parameters: count: 1 path: ../../system/Language/Language.php - - - message: '#^Method CodeIgniter\\Language\\Language\:\:load\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Language/Language.php - - message: '#^Method CodeIgniter\\Language\\Language\:\:parseLine\(\) return type has no value type specified in iterable type array\.$#' count: 1 diff --git a/utils/phpstan-baseline/return.missing.neon b/utils/phpstan-baseline/return.missing.neon index 151fdaa34156..d6cf55ba8d46 100644 --- a/utils/phpstan-baseline/return.missing.neon +++ b/utils/phpstan-baseline/return.missing.neon @@ -1,12 +1,7 @@ -# total 2 errors +# total 1 error parameters: ignoreErrors: - - - message: '#^Method CodeIgniter\\Images\\Handlers\\BaseHandler\:\:__call\(\) should return mixed but return statement is missing\.$#' - count: 1 - path: ../../system/Images/Handlers/BaseHandler.php - - message: '#^Method CodeIgniter\\Test\\Mock\\MockResult\:\:fetchAssoc\(\) should return mixed but return statement is missing\.$#' count: 1