Passed
Push — master ( 62c53d...86bd74 )
by Caen
03:23 queued 14s
created

RouteList::routeToListItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Support\Models;
6
7
use Hyde\Hyde;
8
use Illuminate\Contracts\Support\Arrayable;
9
10
/**
11
 * @internal This class is experimental and is subject to change.
12
 * @experimental This class is experimental and is subject to change.
13
 *
14
 * @see \Hyde\Framework\Testing\Feature\RouteListTest
15
 */
16
class RouteList implements Arrayable
17
{
18
    protected array $routes;
19
20
    public function __construct()
21
    {
22
        $this->routes = $this->generate();
23
    }
24
25
    public function toArray(): array
26
    {
27
        return $this->routes;
28
    }
29
30
    public function headers(): array
31
    {
32
        return array_map(function (string $key): string {
33
            return ucwords(str_replace('_', ' ', $key));
34
        }, array_keys($this->routes[0]));
35
    }
36
37
    protected function generate(): array
38
    {
39
        return collect(Hyde::routes())->map(function (Route $route): array {
40
            return $this->routeToListItem($route)->toArray();
41
        })->values()->toArray();
42
    }
43
44
    protected static function routeToListItem(Route $route): RouteListItem
45
    {
46
        return new RouteListItem($route);
47
    }
48
}
49