Passed
Push — master ( c38b6c...e54c12 )
by Caen
03:47 queued 21s
created

RouteList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A generate() 0 5 1
A routeToListItem() 0 3 1
A __construct() 0 3 1
A headers() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Support\Internal;
6
7
use Hyde\Hyde;
8
use Hyde\Support\Models\Route;
9
use Illuminate\Contracts\Support\Arrayable;
10
11
use function collect;
12
use function ucwords;
13
use function array_map;
14
use function array_keys;
15
use function str_replace;
16
17
/**
18
 * @internal This class is internal and should not be depended on outside the HydePHP framework code.
19
 */
20
class RouteList implements Arrayable
21
{
22
    /** @var array<integer, array<string, string>> */
23
    protected array $routes;
24
25
    public function __construct()
26
    {
27
        $this->routes = $this->generate();
28
    }
29
30
    public function toArray(): array
31
    {
32
        return $this->routes;
33
    }
34
35
    public function headers(): array
36
    {
37
        return array_map(function (string $key): string {
38
            return ucwords(str_replace('_', ' ', $key));
39
        }, array_keys($this->routes[0]));
40
    }
41
42
    protected function generate(): array
43
    {
44
        return collect(Hyde::routes())->map(function (Route $route): array {
45
            return $this->routeToListItem($route)->toArray();
46
        })->values()->toArray();
47
    }
48
49
    protected static function routeToListItem(Route $route): RouteListItem
50
    {
51
        return new RouteListItem($route);
52
    }
53
}
54