Passed
Push — master ( e1642a...3c4285 )
by Anatoly
01:03 queued 12s
created

RouteListCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\Command;
13
14
/**
15
 * Import classes
16
 */
17
use Sunrise\Http\Router\Router;
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
/**
24
 * Import functions
25
 */
26
use function Sunrise\Http\Router\path_plain;
0 ignored issues
show
introduced by
The function Sunrise\Http\Router\path_plain was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
28
/**
29
 * RouteListCommand
30
 *
31
 * @since 2.9.0
32
 */
33
final class RouteListCommand extends Command
34
{
35
36
    /**
37
     * @var Router
38
     */
39
    private $router;
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @param Router $router
45
     * @param null|string $name
46
     */
47 1
    public function __construct(Router $router, ?string $name = null)
48
    {
49 1
        $this->router = $router;
50
51 1
        parent::__construct($name ?? 'router:route-list');
52 1
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public function execute(InputInterface $input, OutputInterface $output) : int
58
    {
59 1
        $table = new Table($output);
60 1
        $table->setStyle('box');
61
62 1
        $table->setHeaders([
63 1
            'Name',
64
            'Host',
65
            'Verb',
66
            'Path',
67
        ]);
68
69 1
        foreach ($this->router->getRoutes() as $route) {
70 1
            $table->addRow([
71 1
                $route->getName(),
72 1
                $route->getHost() ?? 'ANY',
73 1
                \implode(', ', $route->getMethods()),
74 1
                path_plain($route->getPath()),
0 ignored issues
show
Bug introduced by
The function path_plain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
                /** @scrutinizer ignore-call */ 
75
                path_plain($route->getPath()),
Loading history...
75
            ]);
76
        }
77
78 1
        $table->render();
79
80 1
        return 0;
81
    }
82
}
83