Passed
Push — develop ( 734f70...83757e )
by ANTHONIUS
03:38
created

Processor::setCodeCoverageOptions()   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-code-coverage 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\Bridge\CodeCoverage;
15
16
use SebastianBergmann\CodeCoverage\CodeCoverage;
17
use SebastianBergmann\CodeCoverage\Driver\Driver;
18
use SebastianBergmann\CodeCoverage\Filter;
19
20
/**
21
 * Provide bridge to PHP Code Coverage.
22
 */
23
class Processor implements ProcessorInterface
24
{
25
    /**
26
     * @var CodeCoverage
27
     */
28
    private $codeCoverage;
29
30
    /**
31
     * @var TestCase[]
32
     */
33
    private $testCases = [];
34
35
    private $completed = false;
36
37
    /**
38
     * @var Driver
39
     */
40
    private $driver;
41
42
    /**
43
     * @var Filter
44
     */
45
    private $filter;
46
47
    /**
48
     * @var array
49
     */
50
    private $coverageOptions;
51
52
    /**
53
     * @var TestCase
54
     */
55
    private $currentTestCase;
56
57 20
    public function __construct($driver = null, $filter = null)
58
    {
59 20
        $this->driver = $driver;
60 20
        $this->filter = $filter;
61 5
    }
62
63 5
    public function setCurrentTestCase(TestCase $testCase)
64
    {
65 5
        $this->currentTestCase = $testCase;
66
    }
67
68 8
    public function getCurrentTestCase()
69
    {
70 8
        return $this->currentTestCase;
71
    }
72
73 8
    public function setCodeCoverageOptions(array $options)
74
    {
75 8
        $this->coverageOptions = $options;
76 5
    }
77
78 4
    public function getCodeCoverageOptions()
79
    {
80 4
        return $this->coverageOptions;
81
    }
82
83 4
    public function getCodeCoverageFilter()
84
    {
85 4
        return $this->filter;
86
    }
87
88 4
    public function start(TestCase $testCase, $clear = false)
89
    {
90 4
        $this->setCurrentTestCase($testCase);
91 4
        $this->addTestCase($testCase);
92 4
        $this->getCodeCoverage()->start($testCase->getName(), $clear);
93
    }
94
95 88
    public function stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false): array
96
    {
97 88
        return $this->getCodeCoverage()->stop($append, $linesToBeCovered, $linesToBeUsed, $ignoreForceCoversAnnotation);
98
    }
99
100 3
    public function merge($processor)
101
    {
102 3
        $codeCoverage = $processor;
103 3
        if ($processor instanceof self) {
104 3
            $codeCoverage = $processor->getCodeCoverage();
105
        }
106 3
        $this->getCodeCoverage()->merge($codeCoverage);
107
    }
108
109 7
    public function clear()
110
    {
111 7
        $this->getCodeCoverage()->clear();
112 5
    }
113
114 1
    public function setCodeCoverage(CodeCoverage $codeCoverage)
115
    {
116 1
        $this->codeCoverage = $codeCoverage;
117
    }
118
119
    /**
120
     * @return CodeCoverage
121
     */
122 88
    public function getCodeCoverage()
123
    {
124 88
        if (null === $this->codeCoverage) {
125 10
            $this->codeCoverage = new CodeCoverage($this->driver, $this->filter);
126
        }
127
128 88
        return $this->codeCoverage;
129
    }
130
131 84
    public function addTestCase(TestCase $testCase)
132
    {
133 84
        $this->testCases[$testCase->getName()] = $testCase;
134
    }
135
136 4
    public function complete()
137
    {
138 4
        $coverage  = $this->getCodeCoverage();
139 4
        $testCases = $this->testCases;
140 4
        $tests     = $coverage->getTests();
141
142 4
        foreach ($testCases as $testCase) {
143 4
            $name                   = $testCase->getName();
144 4
            $tests[$name]['status'] = $testCase->getResult();
145
        }
146
147 4
        $coverage->setTests($tests);
148 4
        $this->completed = true;
149
    }
150
}
151