Completed
Pull Request — master (#121)
by Marc
03:01
created

DebugCommand::mappingToRows()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 8
cp 0.625
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.2109
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 2
    public function __construct(array $mappings)
19
    {
20 2
        parent::__construct();
21
22 2
        $this->mappings = $mappings;
23 2
    }
24
25 2
    protected function configure()
26
    {
27 2
        $this->setName('debug:tactician');
28 2
    }
29
30 2
    public function execute(InputInterface $input, OutputInterface $output)
31
    {
32 2
        $io = new SymfonyStyle($input, $output);
33
34 2
        $io->title('Tactician routing');
35
36 2
        $headers = ['Command', 'Handler Service'];
37
38 2
        foreach ($this->mappings as $busId => $map) {
39 2
            $io->section('Bus: ' . $busId);
40
41 2
            if (count($map) > 0) {
42 2
                $io->table($headers, $this->mappingToRows($map));
43
            } else {
44 1
                $io->warning("No registered commands for bus $busId");
45
            }
46
        }
47 2
    }
48
49 2
    private function mappingToRows(array $map)
50
    {
51 2
        $rows = [];
52 2
        foreach ($map as $commandName => $handlerService) {
53 2
            $rows[] = [$commandName, $handlerService];
54
        }
55
56 2
        return $rows;
57
    }
58
}
59