CoverageMerger   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 53
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A onProcessParsingCompleted() 0 9 2
A merge() 0 10 2
A getCoverageData() 0 4 1
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);
0 ignored issues
show
Documentation introduced by
$newCoverageData is of type object<SebastianBergmann...eCoverage\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 7
            $this->coverageData = $newCoverageData;
61
        }
62
    }
63
64 7
    public function getCoverageData(): CodeCoverage
65
    {
66 7
        return $this->coverageData;
67
    }
68
}
69