Completed
Push — develop ( 2faf16...be2583 )
by ANTHONIUS
15s queued 11s
created

Processor   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 109
ccs 40
cts 44
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 15

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getCodeCoverageOptions() 0 3 1
A addTestCase() 0 3 1
A setCodeCoverageOptions() 0 3 1
A start() 0 3 1
A stop() 0 3 1
A clear() 0 3 1
A __construct() 0 4 1
A getCodeCoverageFilter() 0 3 1
A getCodeCoverage() 0 7 2
A complete() 0 13 2
A setCodeCoverage() 0 3 1
A merge() 0 7 2
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\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 19
    public function __construct($driver = null, $filter = null)
53
    {
54 19
        $this->driver = $driver;
55 19
        $this->filter = $filter;
56 5
    }
57
58 8
    public function setCodeCoverageOptions(array $options)
59
    {
60 8
        $this->coverageOptions = $options;
61 5
    }
62
63 4
    public function getCodeCoverageOptions()
64
    {
65 4
        return $this->coverageOptions;
66
    }
67
68 4
    public function getCodeCoverageFilter()
69
    {
70 4
        return $this->filter;
71
    }
72
73 4
    public function start(TestCase $testCase, $clear = false)
74
    {
75 4
        $this->getCodeCoverage()->start($testCase->getName(), $clear);
76
    }
77
78 8
    public function stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false): array
79
    {
80 8
        return $this->getCodeCoverage()->stop($append, $linesToBeCovered, $linesToBeUsed, $ignoreForceCoversAnnotation);
81
    }
82
83 3
    public function merge($processor)
84
    {
85 3
        $codeCoverage = $processor;
86 3
        if ($processor instanceof self) {
87 3
            $codeCoverage = $processor->getCodeCoverage();
88
        }
89 3
        $this->getCodeCoverage()->merge($codeCoverage);
90
    }
91
92 7
    public function clear()
93
    {
94 7
        $this->getCodeCoverage()->clear();
95 5
    }
96
97 1
    public function setCodeCoverage(CodeCoverage $codeCoverage)
98
    {
99 1
        $this->codeCoverage = $codeCoverage;
100
    }
101
102
    /**
103
     * @return CodeCoverage
104
     */
105 12
    public function getCodeCoverage()
106
    {
107 12
        if (null === $this->codeCoverage) {
108 10
            $this->codeCoverage = new CodeCoverage($this->driver, $this->filter);
109
        }
110
111 12
        return $this->codeCoverage;
112
    }
113
114 4
    public function addTestCase(TestCase $testCase)
115
    {
116 4
        $this->testCases[$testCase->getName()] = $testCase;
117
    }
118
119 4
    public function complete()
120
    {
121 4
        $coverage  = $this->getCodeCoverage();
122 4
        $testCases = $this->testCases;
123 4
        $tests     = $coverage->getTests();
124
125 4
        foreach ($testCases as $testCase) {
126 4
            $name                   = $testCase->getName();
127 4
            $tests[$name]['status'] = $testCase->getResult();
128
        }
129
130 4
        $coverage->setTests($tests);
131 4
        $this->completed = true;
132
    }
133
}
134