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
|
|
|
|