| Total Complexity | 9 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Router implements RouterInterface |
||
| 15 | { |
||
| 16 | private RouteCollection $routes; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Router constructor. |
||
| 20 | * @param RouteCollection $routes |
||
| 21 | */ |
||
| 22 | public function __construct(RouteCollection $routes) |
||
| 23 | { |
||
| 24 | $this->routes = $routes; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @return RouteCollection |
||
| 29 | */ |
||
| 30 | public function getRouteCollection(): RouteCollection |
||
| 31 | { |
||
| 32 | return $this->routes; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function generate(string $name, array $params = []): string |
||
| 36 | { |
||
| 37 | $routes = $this->routes->getRoutes(); |
||
| 38 | |||
| 39 | foreach ($routes as $route) { |
||
| 40 | $url = $route->generate($name, array_filter($params)); |
||
| 41 | if (null !== $url) { |
||
| 42 | return $url; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | throw new UnableToFoundRouteException($name, $params); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function match(ServerRequestInterface $request): RouteMatch |
||
| 60 | } |
||
| 61 | |||
| 62 | public function addRoute(RouteInterface $route): void |
||
| 65 | } |
||
| 66 | } |