Completed
Push — develop ( 978c73...c86111 )
by ANTHONIUS
13s queued 11s
created

CoverageEvent::setTestCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\CodeCoverage\TestCase;
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 TestCase
30
     */
31
    private $testCase;
32
33
    /**
34
     * @var array
35
     */
36
    private $coverage;
37
38 13
    public function __construct(TestCase $testCase = null)
39
    {
40 13
        $this->testCase   = $testCase;
41 13
        $this->coverage   = [];
42
    }
43
44 3
    public function updateCoverage($coverage)
45
    {
46 3
        $aggregate = $this->coverage;
47
48 3
        foreach ($coverage as $class => $counts) {
49 3
            if (!isset($this->coverage[$class])) {
50 3
                $aggregate[$class] = $counts;
51 3
                continue;
52
            }
53
54 2
            foreach ($counts as $line => $status) {
55 2
                $status                   = !$status ? -1 : ($status > 1 ? 1 : $status);
56 2
                $aggregate[$class][$line] = $status;
57
            }
58
        }
59
60 3
        $this->coverage = $aggregate;
61
    }
62
63 3
    public function setCoverage(array $coverage)
64
    {
65 3
        $this->coverage = $coverage;
66
    }
67
68
    /**
69
     * @return array
70
     */
71 4
    public function getCoverage()
72
    {
73 4
        return $this->coverage;
74
    }
75
76
    /**
77
     * @return TestCase
78
     */
79 3
    public function getTestCase()
80
    {
81 3
        return $this->testCase;
82
    }
83
84
    /**
85
     * @param TestCase $testCase
86
     */
87 3
    public function setTestCase($testCase=null)
88
    {
89 3
        $this->testCase = $testCase;
90
    }
91
}
92