ListRoutes::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Boot\Console\Command;
10
11
use Aura\Router\RouterContainer;
12
use Closure;
13
use Daikon\Boot\Middleware\RoutingHandler;
14
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class ListRoutes extends Command
19
{
20
    private RoutingHandler $routingHandler;
21
22
    public function __construct(RoutingHandler $routingHandler)
23
    {
24
        $this->routingHandler = $routingHandler;
25
26
        parent::__construct();
27
    }
28
29
    protected function configure(): void
30
    {
31
        $this
32
            ->setName('route:ls')
33
            ->setDescription('List registered routes.');
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output): int
37
    {
38
        /** @var Closure $getRouter */
39
        $getRouter = Closure::bind(
40
            function (RoutingHandler $routingHandler): RouterContainer {
41
                /** @psalm-suppress InaccessibleProperty */
42
                return $routingHandler->router;
0 ignored issues
show
Bug introduced by
The property router is declared private in Daikon\Boot\Middleware\RoutingHandler and cannot be accessed from this context.
Loading history...
43
            },
44
            null,
45
            $this->routingHandler
46
        );
47
48
        foreach ($getRouter($this->routingHandler)->getMap()->getRoutes() as $route) {
49
            $output->write("<info>$route->name</info> => ");
50
            $output->write('<comment>'.implode('|', $route->allows).'</comment> ');
51
            $output->writeln($route->path);
52
        }
53
54
        return 0;
55
    }
56
}
57