Passed
Branch master (9c9e82)
by ANTHONIUS
01:35
created

Report::getProcessors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Doyo\Bridge\CodeCoverage;
4
5
use Doyo\Bridge\CodeCoverage\Event\CoverageEvent;
6
use Doyo\Bridge\CodeCoverage\Report\ReportProcessorInterface;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
class Report implements EventSubscriberInterface
10
{
11
    /**
12
     * @var ReportProcessorInterface[]
13
     */
14
    private $processors = [];
15
16 1
    public static function getSubscribedEvents()
17
    {
18
        return [
19 1
            CoverageEvent::report => 'generate'
20
        ];
21
    }
22
23
    /**
24
     * @return ReportProcessorInterface[]
25
     */
26 1
    public function getProcessors(): array
27
    {
28 1
        return $this->processors;
29
    }
30
31 2
    public function addProcessor(ReportProcessorInterface $processor)
32
    {
33 2
        $type = $processor->getType();
34 2
        if(!$this->hasProcessor($type)){
35 2
            $this->processors[$type] = $processor;
36
        }
37
    }
38
39 2
    public function hasProcessor(string $type): bool
40
    {
41 2
        return isset($this->processors[$type]);
42
    }
43
44 1
    public function generate(CoverageEvent $event)
45
    {
46 1
        $consoleIO = $event->getConsoleIO();
47 1
        $processor = $event->getProcessor();
48
49 1
        foreach($this->processors as $reportProcessor){
50 1
            $reportProcessor->process($processor, $consoleIO);
51
        }
52
    }
53
}
54