| Total Complexity | 7 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | final class RouteCollection implements |
||
| 7 | \Countable, |
||
| 8 | \IteratorAggregate |
||
| 9 | { |
||
| 10 | /** @var Route[] */ |
||
| 11 | private $routes = []; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Check if a route exists in the collection. |
||
| 15 | */ |
||
| 16 | 5 | public function has(string $name): bool |
|
| 17 | { |
||
| 18 | 5 | return isset($this->routes[$name]); |
|
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Get a route from the collection. |
||
| 23 | */ |
||
| 24 | 5 | public function get(string $name): Route |
|
| 25 | { |
||
| 26 | 5 | if (! $this->has($name)) { |
|
| 27 | 1 | throw Error\RouteNotSetException::from($name); |
|
| 28 | } |
||
| 29 | |||
| 30 | 4 | return $this->routes[$name]; |
|
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Set a route in the collection. |
||
| 35 | */ |
||
| 36 | 14 | public function set(string $name, Route $route): void |
|
| 39 | 14 | } |
|
| 40 | |||
| 41 | // Countable |
||
| 42 | 2 | public function count(): int |
|
| 43 | { |
||
| 44 | 2 | return count($this->routes); |
|
| 45 | } |
||
| 46 | |||
| 47 | // IteratorAggregate |
||
| 48 | 10 | public function getIterator(): iterable |
|
| 52 | } |
||
| 53 | 10 | } |
|
| 55 |