From 5073e8b4de1163b29b69eba6af4a7db20420daee Mon Sep 17 00:00:00 2001 From: Paulo Esteves Date: Sat, 16 Sep 2023 12:26:33 +0100 Subject: [PATCH 1/3] refactor: Apply PHPStan rule to RouteCollection::__construct() --- system/Router/RouteCollection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 34629920cc1c..afdbe1611dea 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -302,7 +302,8 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing // Normalize the path string in routeFiles array. foreach ($this->routeFiles as $routeKey => $routesFile) { - $this->routeFiles[$routeKey] = realpath($routesFile) ?: $routesFile; + $realpath = realpath($routesFile); + $this->routeFiles[$routeKey] = ($realpath === false) ? $routesFile : $realpath; } } From 26c4035244377520dee19647f5f1646933206493 Mon Sep 17 00:00:00 2001 From: Paulo Esteves Date: Sat, 16 Sep 2023 12:28:04 +0100 Subject: [PATCH 2/3] refactor: Apply PHPStan rule to RouteCollection::loadRoutesOptions() --- system/Router/RouteCollection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index afdbe1611dea..b99ca145106e 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1700,7 +1700,9 @@ public function resetRoutes() */ protected function loadRoutesOptions(?string $verb = null): array { - $verb = $verb ?: $this->getHTTPVerb(); + if (null === $verb || $verb === '') { + $verb = $this->getHTTPVerb(); + } $options = $this->routesOptions[$verb] ?? []; From d736bcff1ad528e5c5cbc34927fb1574e0cfd73c Mon Sep 17 00:00:00 2001 From: Paulo Esteves Date: Sat, 16 Sep 2023 12:45:09 +0100 Subject: [PATCH 3/3] remove exception line from phpstan-baseline for RouteCollection --- phpstan-baseline.php | 5 ----- system/Router/RouteCollection.php | 4 +--- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 106de3723ef0..fc2f43d3005f 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -2316,11 +2316,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Router/RouteCollection.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/Router/RouteCollection.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:add\\(\\) has parameter \\$to with no signature specified for Closure\\.$#', 'count' => 1, diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index b99ca145106e..8a23264058cb 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1700,9 +1700,7 @@ public function resetRoutes() */ protected function loadRoutesOptions(?string $verb = null): array { - if (null === $verb || $verb === '') { - $verb = $this->getHTTPVerb(); - } + $verb ??= $this->getHTTPVerb(); $options = $this->routesOptions[$verb] ?? [];