| Total Complexity | 6 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | final class RouteCollector implements RouteCollectorInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var Group[]|Route[] |
||
| 11 | */ |
||
| 12 | private array $items = []; |
||
| 13 | private array $middlewareDefinitions = []; |
||
| 14 | |||
| 15 | 1 | public function addRoute(Route $route): RouteCollectorInterface |
|
| 16 | { |
||
| 17 | 1 | $this->items[] = $route; |
|
| 18 | 1 | return $this; |
|
| 19 | } |
||
| 20 | |||
| 21 | 9 | public function addGroup(Group $group): RouteCollectorInterface |
|
| 22 | { |
||
| 23 | 9 | $this->items[] = $group; |
|
| 24 | 9 | return $this; |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Appends a handler middleware definition that should be invoked for a matched route. |
||
| 29 | * First added handler will be executed first. |
||
| 30 | * |
||
| 31 | * @param mixed $middlewareDefinition |
||
| 32 | * |
||
| 33 | * @return self |
||
| 34 | */ |
||
| 35 | 1 | public function middleware($middlewareDefinition): RouteCollectorInterface |
|
| 36 | { |
||
| 37 | 1 | array_unshift($this->middlewareDefinitions, $middlewareDefinition); |
|
| 38 | 1 | return $this; |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Prepends a handler middleware definition that should be invoked for a matched route. |
||
| 43 | * First added handler will be executed last. |
||
| 44 | * |
||
| 45 | * @param mixed $middlewareDefinition |
||
| 46 | * |
||
| 47 | * @return self |
||
| 48 | */ |
||
| 49 | 1 | public function prependMiddleware($middlewareDefinition): RouteCollectorInterface |
|
| 50 | { |
||
| 51 | 1 | $this->middlewareDefinitions[] = $middlewareDefinition; |
|
| 52 | 1 | return $this; |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return Group[]|Route[] |
||
| 57 | */ |
||
| 58 | 10 | public function getItems(): array |
|
| 61 | } |
||
| 62 | |||
| 63 | 9 | public function getMiddlewareDefinitions(): array |
|
| 66 | } |
||
| 67 | } |
||
| 68 |