Completed
Push — master ( 1a3a48...6e0e69 )
by Alessandro
09:39 queued 07:07
created

CoverageMerger::onProcessParsingCompleted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
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 Paraunit\Proxy\Coverage\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 */
22
    private $coverageData;
23
24
    /**
25
     * CoverageMerger constructor.
26
     * @param CoverageFetcher $coverageFetcher
27
     */
28 12
    public function __construct(CoverageFetcher $coverageFetcher)
29
    {
30 12
        $this->coverageFetcher = $coverageFetcher;
31
    }
32
33 11
    public static function getSubscribedEvents(): array
34
    {
35
        return [
36 11
            ProcessEvent::PROCESS_PARSING_COMPLETED => 'onProcessParsingCompleted',
37
        ];
38
    }
39
40
    /**
41
     * @param ProcessEvent $processEvent
42
     */
43 3
    public function onProcessParsingCompleted(ProcessEvent $processEvent)
44
    {
45 3
        $process = $processEvent->getProcess();
46 3
        if ($process->isToBeRetried()) {
47
            return;
48
        }
49
50 3
        $this->merge($process);
51
    }
52
53 3
    private function merge(AbstractParaunitProcess $process)
54
    {
55 3
        $newCoverageData = $this->coverageFetcher->fetch($process);
56
57 3
        if ($this->coverageData instanceof CodeCoverage) {
58 1
            $this->coverageData->merge($newCoverageData);
0 ignored issues
show
Documentation introduced by
$newCoverageData is of type object<Paraunit\Proxy\Coverage\CodeCoverage>, but the function expects a object<self>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
        } else {
60 3
            $this->coverageData = $newCoverageData;
61
        }
62
    }
63
64 3
    public function getCoverageData(): CodeCoverage
65
    {
66 3
        return $this->coverageData;
67
    }
68
}
69