Passed
Push — main ( dd4eea...91afa7 )
by Dimitri
03:22
created

AutoRouteCollector::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 25
rs 9.7666
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Cli\Commands\Routes;
13
14
/**
15
 * Collecte des données pour la liste des routes automatiques.
16
 */
17
final class AutoRouteCollector
18
{
19
    /**
20
     * @param string $namespace Namespace dans lequel on recherche
21
     */
22
    public function __construct(private string $namespace, private string $defaultController, private string $defaultMethod)
23
    {
24
    }
25
26
    /**
27
     * @return array<int, array<int, string>>
28
     * @phpstan-return list<list<string>>
29
     */
30
    public function get(): array
31
    {
32
        $finder = new ControllerFinder($this->namespace);
33
        $reader = new ControllerMethodReader($this->namespace);
34
35
        $tbody = [];
36
37
        foreach ($finder->find() as $class) {
38
            $output = $reader->read(
39
                $class,
40
                $this->defaultController,
41
                $this->defaultMethod
42
            );
43
44
            foreach ($output as $item) {
45
                $tbody[] = [
46
                    'auto',
47
                    $item['route'],
48
                    '',
49
                    $item['handler'],
50
                ];
51
            }
52
        }
53
54
        return $tbody;
55
    }
56
}
57