Completed
Pull Request — master (#9)
by
unknown
09:56
created

DebugCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace BornFree\TacticianDomainEventBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
10
class DebugCommand extends Command
11
{
12
    /**
13
     * @var array
14
     */
15
    private $mappings;
16
17
    public function __construct(array $mappings)
18
    {
19
        parent::__construct();
20
21
        $this->mappings = $mappings;
22
    }
23
24
    protected function configure()
25
    {
26
        $this->setName('debug:tactician-domain-events');
27
    }
28
29
    public function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $io = new SymfonyStyle($input, $output);
32
33
        $io->title('Tactician domain events');
34
        $headers = ['Order', 'Callable'];
35
36
        foreach ($this->mappings as $event => $listeners) {
37
            $io->section('Event: '.$event);
38
            $io->table($headers, $this->mappingToRows($listeners));
39
        }
40
41
        $io->comment('Number of events: '. count($this->mappings));
42
    }
43
44
    private function mappingToRows(array $listeners)
45
    {
46
        $rows = [];
47
        foreach ($listeners as $idx => $listener) {
48
            $rows[] = ['#'.($idx+1), $listener];
49
        }
50
51
        return $rows;
52
    }
53
}
54