Passed
Pull Request — develop (#5)
by ANTHONIUS
04:10
created

CoverageEvent::updateCoverage()   A

Complexity

Conditions 6
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.972

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 3
nop 1
dl 0
loc 18
ccs 7
cts 10
cp 0.7
crap 6.972
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
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\Behat\Coverage\Event;
15
16
use Doyo\Behat\Coverage\Bridge\Aggregate;
0 ignored issues
show
Bug introduced by
The type Doyo\Behat\Coverage\Bridge\Aggregate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Doyo\Behat\Coverage\Bridge\Symfony\Event;
18
19
class CoverageEvent extends Event
20
{
21
    const BEFORE_START   = 'doyo.coverage.start.pre';
22
    const BEFORE_STOP    = 'doyo.coverage.stop.pre';
23
    const BEFORE_REFRESH = 'doyo.coverage.refresh.pre';
24
    const START          = 'doyo.coverage.start';
25
    const STOP           = 'doyo.coverage.stop';
26
    const REFRESH        = 'doyo.coverage.refresh';
27
28
    /**
29
     * @var string
30
     */
31
    private $coverageId;
32
33
    /**
34
     * @var array
35
     */
36
    private $coverage;
37
38 9
    public function __construct($coverageId = null)
39
    {
40 9
        $this->coverageId = $coverageId;
41 9
        $this->coverage  = array();
42
    }
43
44 1
    public function updateCoverage($coverage)
45
    {
46 1
        $aggregate = $this->coverage;
47
48 1
        foreach ($coverage as $class => $counts) {
49
50 1
            if(!isset($this->coverage[$class])){
51 1
                $aggregate[$class] = $counts;
52 1
                continue;
53
            }
54
55
            foreach($counts as $line => $status){
56
                $status = !$status ? -1 : ($status > 1 ? 1 : $status);
57
                $aggregate[$class][$line] = $status;
58
            }
59
        }
60
61 1
        $this->coverage = $aggregate;
62
    }
63
64 1
    public function setCoverage(array $coverage)
65
    {
66 1
        $this->coverage = $coverage;
67
    }
68
69
    /**
70
     * @return array
71
     */
72 1
    public function getCoverage()
73
    {
74 1
        return $this->coverage;
75
    }
76
77
    /**
78
     * @return string
79
     */
80 1
    public function getCoverageId(): string
81
    {
82 1
        return $this->coverageId;
83
    }
84
85
    /**
86
     * @param string|null $coverageId
87
     */
88 1
    public function setCoverageId($coverageId=null)
89
    {
90 1
        $this->coverageId = $coverageId;
91
    }
92
}
93