From ee34c18444d9e4df9f11f9b64c05eacc0e24caec Mon Sep 17 00:00:00 2001 From: Hsuan Date: Wed, 9 Aug 2023 22:16:28 +0800 Subject: [PATCH] Fix: Remove the ignore errors of Router in phpstan. --- phpstan-baseline.php | 45 ------------------------------- system/Router/AutoRouter.php | 2 ++ system/Router/RouteCollection.php | 8 ++++++ system/Router/Router.php | 8 ++++++ 4 files changed, 18 insertions(+), 45 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 6d22593ffcab..cf668e9a20dd 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1171,11 +1171,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Model.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouter\\:\\:setDirectory\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/AutoRouter.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Router\\\\AutoRouter\\:\\:\\$cliRoutes type has no signature specified for Closure\\.$#', 'count' => 1, @@ -1191,11 +1186,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/RouteCollection.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:create\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/RouteCollection.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:create\\(\\) has parameter \\$to with no signature specified for Closure\\.$#', 'count' => 1, @@ -1206,11 +1196,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/RouteCollection.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:discoverRoutes\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/RouteCollection.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:environment\\(\\) has parameter \\$callback with no signature specified for Closure\\.$#', 'count' => 1, @@ -1231,11 +1216,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/RouteCollection.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:group\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/RouteCollection.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:group\\(\\) has parameter \\$params with no signature specified for callable\\.$#', 'count' => 1, @@ -1271,11 +1251,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/RouteCollection.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:resetRoutes\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/RouteCollection.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:set404Override\\(\\) has parameter \\$callable with no signature specified for callable\\.$#', 'count' => 1, @@ -1341,11 +1316,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/Router.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\Router\\:\\:autoRoute\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/Router.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\Router\\:\\:controllerName\\(\\) return type has no signature specified for Closure\\.$#', 'count' => 1, @@ -1361,26 +1331,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/Router.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\Router\\:\\:setDefaultController\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/Router.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\Router\\:\\:setDirectory\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/Router.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\Router\\:\\:setMatchedRoute\\(\\) has parameter \\$handler with no signature specified for callable\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Router/Router.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Router\\\\Router\\:\\:setRequest\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Router/Router.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Router\\\\Router\\:\\:\\$controller type has no signature specified for Closure\\.$#', 'count' => 1, diff --git a/system/Router/AutoRouter.php b/system/Router/AutoRouter.php index 1475def4fb53..f7cd02a3d329 100644 --- a/system/Router/AutoRouter.php +++ b/system/Router/AutoRouter.php @@ -254,6 +254,8 @@ private function isValidSegment(string $segment): bool * @param bool $validate if true, checks to make sure $dir consists of only PSR4 compliant segments * * @deprecated This method should be removed. + * + * @return void */ public function setDirectory(?string $dir = null, bool $append = false, bool $validate = true) { diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 488315193454..8fa3054edf1d 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -274,6 +274,8 @@ public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php') /** * Will attempt to discover any additional routes, either through * the local PSR4 namespaces, or through selected Composer packages. + * + * @return void */ protected function discoverRoutes() { @@ -659,6 +661,8 @@ public function getRedirectCode(string $from): int * * @param string $name The name to group/prefix the routes with. * @param array|callable ...$params + * + * @return void */ public function group(string $name, ...$params) { @@ -1291,6 +1295,8 @@ private function replaceLocale(string $route, ?string $locale = null): string * by a pipe character "|" if there is more than one. * * @param array|Closure|string $to + * + * @return void */ protected function create(string $verb, string $from, $to, ?array $options = null) { @@ -1536,6 +1542,8 @@ private function determineCurrentSubdomain() /** * Reset the routes, so that a test case can provide the * explicit ones needed for it. + * + * @return void */ public function resetRoutes() { diff --git a/system/Router/Router.php b/system/Router/Router.php index f0b9d2c9aab5..5dee59b31c25 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -503,6 +503,8 @@ protected function checkRoutes(string $uri): bool * * Attempts to match a URI path against Controllers and directories * found in APPPATH/Controllers, to find a matching route. + * + * @return void */ public function autoRoute(string $uri) { @@ -579,6 +581,8 @@ protected function scanControllers(array $segments): array * * @param bool $validate if true, checks to make sure $dir consists of only PSR4 compliant segments * + * @return void + * * @deprecated This method should be removed. */ public function setDirectory(?string $dir = null, bool $append = false, bool $validate = true) @@ -611,6 +615,8 @@ private function isValidSegment(string $segment): bool * to be called. * * @param array $segments URI segments + * + * @return void */ protected function setRequest(array $segments = []) { @@ -638,6 +644,8 @@ protected function setRequest(array $segments = []) * Sets the default controller based on the info set in the RouteCollection. * * @deprecated This was an unnecessary method, so it is no longer used. + * + * @return void */ protected function setDefaultController() {