Skip to content

Commit

Permalink
refactor: Fix phpstan return.type
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 committed Jan 7, 2025
1 parent d24e64a commit 8f6a8c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 24 additions & 2 deletions tests/system/Commands/Utilities/Routes/FilterFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -118,6 +122,9 @@ public function testFindGlobalsFilters(): void

public function testFindGlobalsFiltersWithRedirectRoute(): void
{
/**
* @var RouteCollection $collection
*/
$collection = $this->createRouteCollection();
$collection->addRedirect('users/about', 'profile');

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8f6a8c0

Please sign in to comment.