From d24e64ab0e299e7ceb0fccbc4178062709a235de Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Sun, 5 Jan 2025 19:17:27 +0300 Subject: [PATCH 1/2] refactor: Fix phpstan return.type --- system/Router/RouteCollection.php | 2 +- utils/phpstan-baseline/loader.neon | 1 - utils/phpstan-baseline/return.type.neon | 8 -------- 3 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 utils/phpstan-baseline/return.type.neon diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index faee291a8213..c04d1e7ce918 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -652,7 +652,7 @@ public function setHTTPVerb(string $verb) * It does not allow any options to be set on the route, or to * define the method used. */ - public function map(array $routes = [], ?array $options = null): RouteCollectionInterface + public function map(array $routes = [], ?array $options = null): static { foreach ($routes as $from => $to) { $this->add($from, $to, $options); diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index feab1b53df83..44c446bd2634 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -45,7 +45,6 @@ includes: - property.readOnlyByPhpDocDefaultValue.neon - property.unusedType.neon - return.missing.neon - - return.type.neon - return.unusedType.neon - staticMethod.notFound.neon - ternary.shortNotAllowed.neon diff --git a/utils/phpstan-baseline/return.type.neon b/utils/phpstan-baseline/return.type.neon deleted file mode 100644 index caa1d6784249..000000000000 --- a/utils/phpstan-baseline/return.type.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 1 error - -parameters: - ignoreErrors: - - - message: '#^Method CodeIgniter\\Commands\\Utilities\\Routes\\FilterFinderTest\:\:createRouteCollection\(\) should return CodeIgniter\\Router\\RouteCollection but returns CodeIgniter\\Router\\RouteCollectionInterface\.$#' - count: 1 - path: ../../tests/system/Commands/Utilities/Routes/FilterFinderTest.php From 8f6a8c03a39a08deb18c782a9154e85980bfdb31 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Tue, 7 Jan 2025 22:14:42 +0300 Subject: [PATCH 2/2] refactor: Fix phpstan return.type --- system/Router/RouteCollection.php | 2 +- .../Utilities/Routes/FilterFinderTest.php | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index c04d1e7ce918..faee291a8213 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -652,7 +652,7 @@ public function setHTTPVerb(string $verb) * It does not allow any options to be set on the route, or to * define the method used. */ - public function map(array $routes = [], ?array $options = null): static + public function map(array $routes = [], ?array $options = null): RouteCollectionInterface { foreach ($routes as $from => $to) { $this->add($from, $to, $options); diff --git a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php index 7bba11d9c968..d300c78993d1 100644 --- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php +++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php @@ -21,6 +21,7 @@ use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Response; use CodeIgniter\Router\RouteCollection; +use CodeIgniter\Router\RouteCollectionInterface; use CodeIgniter\Router\Router; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\ConfigFromArrayTrait; @@ -53,7 +54,7 @@ protected function setUp(): void $this->moduleConfig->enabled = false; } - private function createRouteCollection(array $routes = []): RouteCollection + private function createRouteCollection(array $routes = []): RouteCollectionInterface { $collection = new RouteCollection(service('locator'), $this->moduleConfig, new Routing()); @@ -66,7 +67,7 @@ private function createRouteCollection(array $routes = []): RouteCollection return $collection->map($routes); } - private function createRouter(RouteCollection $collection): Router + private function createRouter(RouteCollectionInterface $collection): Router { return new Router($collection, $this->request); } @@ -101,6 +102,9 @@ private function createFilters(array $config = []): Filters public function testFindGlobalsFilters(): void { + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection(); $router = $this->createRouter($collection); $filters = $this->createFilters(); @@ -118,6 +122,9 @@ public function testFindGlobalsFilters(): void public function testFindGlobalsFiltersWithRedirectRoute(): void { + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection(); $collection->addRedirect('users/about', 'profile'); @@ -137,6 +144,9 @@ public function testFindGlobalsFiltersWithRedirectRoute(): void public function testFindGlobalsAndRouteFilters(): void { + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection(); $collection->get('admin', ' AdminController::index', ['filter' => 'honeypot']); $router = $this->createRouter($collection); @@ -155,6 +165,9 @@ public function testFindGlobalsAndRouteFilters(): void public function testFindGlobalsAndRouteClassnameFilters(): void { + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection(); $collection->get('admin', ' AdminController::index', ['filter' => InvalidChars::class]); $router = $this->createRouter($collection); @@ -173,6 +186,9 @@ public function testFindGlobalsAndRouteClassnameFilters(): void public function testFindGlobalsAndRouteMultipleFilters(): void { + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection(); $collection->get('admin', ' AdminController::index', ['filter' => ['honeypot', InvalidChars::class]]); $router = $this->createRouter($collection); @@ -191,6 +207,9 @@ public function testFindGlobalsAndRouteMultipleFilters(): void public function testFilterOrder(): void { + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection([]); $collection->get('/', ' Home::index', ['filter' => ['route1', 'route2']]); $router = $this->createRouter($collection); @@ -256,6 +275,9 @@ public function testFilterOrderWithOldFilterOrder(): void $feature = config(Feature::class); $feature->oldFilterOrder = true; + /** + * @var RouteCollection $collection + */ $collection = $this->createRouteCollection([]); $collection->get('/', ' Home::index', ['filter' => ['route1', 'route2']]); $router = $this->createRouter($collection);