| Conditions | 9 |
| Paths | 7 |
| Total Lines | 45 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 9.111 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 36 | public function collect(bool $reset = true): array |
||
| 37 | { |
||
| 38 | if (! $reset && $this->cachedRoutes !== []) { |
||
| 39 | return $this->cachedRoutes; |
||
| 40 | } |
||
| 41 | |||
| 42 | $methods = [ |
||
| 43 | 'get', |
||
| 44 | 'head', |
||
| 45 | 'post', |
||
| 46 | 'patch', |
||
| 47 | 'put', |
||
| 48 | 'delete', |
||
| 49 | 'options', |
||
| 50 | 'trace', |
||
| 51 | 'connect', |
||
| 52 | 'cli', |
||
| 53 | 2 | ]; |
|
| 54 | |||
| 55 | 2 | $definedRoutes = []; |
|
| 56 | |||
| 57 | foreach ($methods as $method) { |
||
| 58 | 2 | $routes = $this->routeCollection->getRoutes($method); |
|
| 59 | |||
| 60 | foreach ($routes as $route => $handler) { |
||
| 61 | if (is_string($handler) || $handler instanceof Closure) { |
||
| 62 | if ($handler instanceof Closure) { |
||
| 63 | 2 | $view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false; |
|
| 64 | |||
| 65 | 2 | $handler = $view ? '(View) ' . $view : '(Closure)'; |
|
| 66 | } |
||
| 67 | |||
| 68 | 2 | $routeName = $this->routeCollection->getRoutesOptions($route, $method)['as'] ?? $route; |
|
| 69 | |||
| 70 | $definedRoutes[] = [ |
||
| 71 | 'method' => $method, |
||
| 72 | 'route' => $route, |
||
| 73 | 'name' => $routeName, |
||
| 74 | 'handler' => $handler, |
||
| 75 | 2 | ]; |
|
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | 2 | return $this->cachedRoutes = $definedRoutes; |
|
| 81 | } |
||
| 83 |