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

DebugCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 4 1
A execute() 0 14 2
A mappingToRows() 0 9 2
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