Report::hasProcessor()   A
last analyzed

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 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Bridge\CodeCoverage;
15
16
use Doyo\Bridge\CodeCoverage\Event\CoverageEvent;
17
use Doyo\Bridge\CodeCoverage\Report\ReportProcessorInterface;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
class Report implements EventSubscriberInterface
21
{
22
    /**
23
     * @var ReportProcessorInterface[]
24
     */
25
    private $processors = [];
26
27 3
    public static function getSubscribedEvents()
28
    {
29
        return [
30 3
            CoverageEvent::report => 'generate',
31
        ];
32
    }
33
34
    /**
35
     * @return ReportProcessorInterface[]
36
     */
37 1
    public function getProcessors(): array
38
    {
39 1
        return $this->processors;
40
    }
41
42 3
    public function addProcessor(ReportProcessorInterface $processor)
43
    {
44 3
        $type = $processor->getType();
45 3
        if (!$this->hasProcessor($type)) {
46 3
            $this->processors[$type] = $processor;
47
        }
48
    }
49
50 3
    public function hasProcessor(string $type): bool
51
    {
52 3
        return isset($this->processors[$type]);
53
    }
54
55 2
    public function generate(CoverageEvent $event)
56
    {
57 2
        $consoleIO = $event->getConsoleIO();
58 2
        $processor = $event->getProcessor();
59
60 2
        $consoleIO->coverageSection('processing code coverage reports');
61
62 2
        foreach ($this->processors as $reportProcessor) {
63 2
            $reportProcessor->process($processor, $consoleIO);
64
        }
65
    }
66
}
67