|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Paraunit\Coverage; |
|
6
|
|
|
|
|
7
|
|
|
use Paraunit\Lifecycle\ProcessEvent; |
|
8
|
|
|
use Paraunit\Process\AbstractParaunitProcess; |
|
9
|
|
|
use SebastianBergmann\CodeCoverage\CodeCoverage; |
|
10
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class CoverageMerger |
|
14
|
|
|
* @package Paraunit\Coverage |
|
15
|
|
|
*/ |
|
16
|
|
|
class CoverageMerger implements EventSubscriberInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var CoverageFetcher */ |
|
19
|
|
|
private $coverageFetcher; |
|
20
|
|
|
|
|
21
|
|
|
/** @var CodeCoverage|null */ |
|
22
|
|
|
private $coverageData; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* CoverageMerger constructor. |
|
26
|
|
|
* @param CoverageFetcher $coverageFetcher |
|
27
|
|
|
*/ |
|
28
|
16 |
|
public function __construct(CoverageFetcher $coverageFetcher) |
|
29
|
|
|
{ |
|
30
|
16 |
|
$this->coverageFetcher = $coverageFetcher; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
15 |
|
public static function getSubscribedEvents(): array |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
15 |
|
ProcessEvent::PROCESS_PARSING_COMPLETED => 'onProcessParsingCompleted', |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param ProcessEvent $processEvent |
|
42
|
|
|
*/ |
|
43
|
7 |
|
public function onProcessParsingCompleted(ProcessEvent $processEvent) |
|
44
|
|
|
{ |
|
45
|
7 |
|
$process = $processEvent->getProcess(); |
|
46
|
7 |
|
if ($process->isToBeRetried()) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
7 |
|
$this->merge($process); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
7 |
|
private function merge(AbstractParaunitProcess $process) |
|
54
|
|
|
{ |
|
55
|
7 |
|
$newCoverageData = $this->coverageFetcher->fetch($process); |
|
56
|
|
|
|
|
57
|
7 |
|
if ($this->coverageData instanceof CodeCoverage) { |
|
58
|
1 |
|
$this->coverageData->merge($newCoverageData); |
|
|
|
|
|
|
59
|
|
|
} else { |
|
60
|
7 |
|
$this->coverageData = $newCoverageData; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
7 |
|
public function getCoverageData(): CodeCoverage |
|
65
|
|
|
{ |
|
66
|
7 |
|
return $this->coverageData; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: