Skip to content

Commit 74056b6

Browse files
authored
Merge pull request #7129 from kenjis/add-phpdoc-type-RouteCollection
refactor: add PHPDoc types in RouteCollection
2 parents 7be2371 + 991151c commit 74056b6

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

system/Router/RouteCollection.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ class RouteCollection implements RouteCollectionInterface
112112
* verb => [
113113
* routeName => [
114114
* 'route' => [
115-
* routeKey(or from) => handler,
116-
* ]
115+
* routeKey(regex) => handler,
116+
* ],
117+
* 'redirect' => statusCode,
117118
* ]
118119
* ],
119120
* ]
@@ -138,7 +139,7 @@ class RouteCollection implements RouteCollectionInterface
138139
*
139140
* [
140141
* verb => [
141-
* routeKey(or from) => [
142+
* routeKey(regex) => [
142143
* key => value,
143144
* ]
144145
* ],
@@ -527,6 +528,8 @@ public function getRoutes(?string $verb = null): array
527528

528529
/**
529530
* Returns one or all routes options
531+
*
532+
* @return array<string, int|string> [key => value]
530533
*/
531534
public function getRoutesOptions(?string $from = null, ?string $verb = null): array
532535
{
@@ -1149,20 +1152,25 @@ public function getFilterForRoute(string $search, ?string $verb = null): string
11491152
* 'role:admin,manager'
11501153
*
11511154
* has a filter of "role", with parameters of ['admin', 'manager'].
1155+
*
1156+
* @param string $search routeKey
1157+
*
1158+
* @return array<int, string> filter_name or filter_name:arguments like 'role:admin,manager'
1159+
* @phpstan-return list<string>
11521160
*/
11531161
public function getFiltersForRoute(string $search, ?string $verb = null): array
11541162
{
11551163
$options = $this->loadRoutesOptions($verb);
11561164

1157-
if (! array_key_exists($search, $options)) {
1165+
if (! array_key_exists($search, $options) || ! array_key_exists('filter', $options[$search])) {
11581166
return [];
11591167
}
11601168

11611169
if (is_string($options[$search]['filter'])) {
11621170
return [$options[$search]['filter']];
11631171
}
11641172

1165-
return $options[$search]['filter'] ?? [];
1173+
return $options[$search]['filter'];
11661174
}
11671175

11681176
/**
@@ -1520,6 +1528,16 @@ public function resetRoutes()
15201528

15211529
/**
15221530
* Load routes options based on verb
1531+
*
1532+
* @return array<string, array<string, array|int|string>> [routeKey(or from) => [key => value]]
1533+
* @phpstan-return array<
1534+
* string,
1535+
* array{
1536+
* filter?: string|list<string>, namespace?: string, hostname?: string,
1537+
* subdomain?: string, offset?: int, priority?: int, as?: string,
1538+
* redirect?: string
1539+
* }
1540+
* >
15231541
*/
15241542
protected function loadRoutesOptions(?string $verb = null): array
15251543
{

0 commit comments

Comments
 (0)