DebugCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace League\Tactician\Bundle\Command;
5
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Style\SymfonyStyle;
10
11
class DebugCommand extends Command
12
{
13
    /**
14
     * @var array
15
     */
16
    private $mappings;
17
18 3
    public function __construct(array $mappings)
19
    {
20 3
        parent::__construct();
21
22 3
        $this->mappings = $mappings;
23 3
    }
24
25 3
    protected function configure()
26
    {
27 3
        $this->setName('debug:tactician');
28 3
    }
29
30 3
    public function execute(InputInterface $input, OutputInterface $output)
31
    {
32 3
        $io = new SymfonyStyle($input, $output);
33
34 3
        $io->title('Tactician routing');
35
36 3
        $headers = ['Command', 'Handler Service'];
37
38 3
        foreach ($this->mappings as $busId => $map) {
39 3
            $io->section('Bus: ' . $busId);
40
41 3
            if (count($map) > 0) {
42 3
                $io->table($headers, $this->mappingToRows($map));
43
            } else {
44 2
                $io->warning("No registered commands for bus $busId");
45
            }
46
        }
47 3
48
        return 0;
49 3
    }
50
51 3
    private function mappingToRows(array $map)
52 3
    {
53 3
        $rows = [];
54
        foreach ($map as $commandName => $handlerService) {
55
            $rows[] = [$commandName, $handlerService];
56 3
        }
57
58
        return $rows;
59
    }
60
}
61