Skip to content

Commit 2ac2615

Browse files
authored
refactor: fix phpstan errors in Router (#10460)
1 parent d608eaf commit 2ac2615

13 files changed

Lines changed: 115 additions & 574 deletions

system/Router/Attributes/Filter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
3939
class Filter implements RouteAttributeInterface
4040
{
41+
/**
42+
* @param array<array-key, scalar> $having
43+
*/
4144
public function __construct(
4245
public string $by,
4346
public array $having = [],
@@ -56,6 +59,9 @@ public function after(RequestInterface $request, ResponseInterface $response): ?
5659
return null;
5760
}
5861

62+
/**
63+
* @return list<string>
64+
*/
5965
public function getFilters(): array
6066
{
6167
if ($this->having === []) {

system/Router/Attributes/Restrict.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
4343
class Restrict implements RouteAttributeInterface
4444
{
45+
/**
46+
* @param list<string>|string|null $environment
47+
* @param list<string>|string|null $hostname
48+
* @param list<string>|string|null $subdomain
49+
*/
4550
public function __construct(
4651
public array|string|null $environment = null,
4752
public array|string|null $hostname = null,

system/Router/AutoRouter.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ public function __construct(
5555
) {
5656
}
5757

58-
/**
59-
* Attempts to match a URI path against Controllers and directories
60-
* found in APPPATH/Controllers, to find a matching route.
61-
*
62-
* @param string $httpVerb HTTP verb like `GET`,`POST`
63-
*
64-
* @return array [directory_name, controller_name, controller_method, params]
65-
*/
6658
public function getRoute(string $uri, string $httpVerb): array
6759
{
6860
$segments = explode('/', $uri);
@@ -95,7 +87,7 @@ public function getRoute(string $uri, string $httpVerb): array
9587
throw PageNotFoundException::forPageNotFound();
9688
}
9789

98-
/** @var array $params An array of params to the controller method. */
90+
/** @var list<string> $params An array of params to the controller method. */
9991
$params = [];
10092

10193
if ($segments !== []) {
@@ -177,11 +169,12 @@ public function setTranslateURIDashes(bool $val = false): self
177169
}
178170

179171
/**
180-
* Scans the controller directory, attempting to locate a controller matching the supplied uri $segments
172+
* Scans the controller directory, attempting to locate a controller matching the supplied uri `$segments`.
173+
* Returns an array of remaining uri segments that don't map onto a directory.
181174
*
182-
* @param array $segments URI segments
175+
* @param list<string> $segments URI segments
183176
*
184-
* @return array returns an array of remaining uri segments that don't map onto a directory
177+
* @return list<string>
185178
*/
186179
private function scanControllers(array $segments): array
187180
{

system/Router/AutoRouterImproved.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ final class AutoRouterImproved implements AutoRouterInterface
6363
* Map of URI segments and namespaces.
6464
*
6565
* The key is the first URI segment. The value is the controller namespace.
66-
* E.g.,
67-
* [
68-
* 'blog' => 'Acme\Blog\Controllers',
69-
* ]
66+
* ```
67+
* ['blog' => 'Acme\Blog\Controllers']
68+
* ```
7069
*
71-
* @var array [ uri_segment => namespace ]
70+
* @var array<string, string>
7271
*/
7372
private array $moduleRoutes;
7473

@@ -133,6 +132,9 @@ public function __construct(
133132
$this->controller = $this->defaultController;
134133
}
135134

135+
/**
136+
* @return list<string>
137+
*/
136138
private function createSegments(string $uri): array
137139
{
138140
$segments = explode('/', $uri);
@@ -250,13 +252,6 @@ private function searchLastDefaultController(): bool
250252
return false;
251253
}
252254

253-
/**
254-
* Finds controller, method and params from the URI.
255-
*
256-
* @param string $httpVerb HTTP verb like `GET`,`POST`
257-
*
258-
* @return array [directory_name, controller_name, controller_method, params]
259-
*/
260255
public function getRoute(string $uri, string $httpVerb): array
261256
{
262257
$this->uri = $uri;

system/Router/AutoRouterInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
interface AutoRouterInterface
2020
{
2121
/**
22-
* Returns controller, method and params from the URI.
22+
* Returns the directory name, controller name, controller method, and any parameters for the given URI and HTTP verb.
2323
*
24-
* @return array [directory_name, controller_name, controller_method, params]
24+
* @param string $httpVerb HTTP verb like `GET`,`POST`
25+
*
26+
* @return array{string|null, string, string, list<string>}
2527
*/
2628
public function getRoute(string $uri, string $httpVerb): array;
2729
}

0 commit comments

Comments
 (0)