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

CoverageEvent   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 71
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

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