RouterListRoutesCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 33
ccs 17
cts 17
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 21 2
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\Command;
15
16
use Sunrise\Http\Router\RouterInterface;
17
use Symfony\Component\Console\Attribute\AsCommand;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Helper\Table;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
use function implode;
24
25
/**
26
 * @since 2.9.0
27
 */
28
#[AsCommand('router:list-routes', 'Lists routes.')]
29
final class RouterListRoutesCommand extends Command
30
{
31 1
    public function __construct(
32
        private readonly RouterInterface $router,
33
    ) {
34 1
        parent::__construct();
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40 1
    protected function execute(InputInterface $input, OutputInterface $output): int
41
    {
42 1
        $table = new Table($output);
43
44 1
        $table->setHeaders([
45 1
            'NAME',
46 1
            'PATH',
47 1
            'METHOD(S)',
48 1
        ]);
49
50 1
        foreach ($this->router->getRoutes() as $route) {
51 1
            $table->addRow([
52 1
                $route->getName(),
53 1
                $route->getPath(),
54 1
                implode(', ', $route->getMethods()),
55 1
            ]);
56
        }
57
58 1
        $table->render();
59
60 1
        return self::SUCCESS;
61
    }
62
}
63