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

Processor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 88%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 65
ccs 22
cts 25
cp 0.88
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addTestCase() 0 3 1
A start() 0 3 1
A __construct() 0 4 1
A getCodeCoverage() 0 3 1
A complete() 0 13 2
A __call() 0 7 2
A setCodeCoverage() 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\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
 * @method        append(array $data, $id = null, $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], $ignoreForceCoversAnnotation = false)
24
 * @method        setAddUncoveredFilesFromWhitelist(bool $flag)
25
 * @method        clear()
26
 * @method array  getTests()
27
 * @method Driver getDriver()
28
 * @method Filter filter()
29
 * @method array  stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false)
30
 */
31
class Processor
32
{
33
    /**
34
     * @var CodeCoverage
35
     */
36
    private $codeCoverage;
37
38
    /**
39
     * @var TestCase[]
40
     */
41
    private $testCases;
42
43
    private $completed = false;
44
45 18
    public function __construct($driver = null, $filter = null)
46
    {
47 18
        $codeCoverage       = new CodeCoverage($driver, $filter);
48 18
        $this->codeCoverage = $codeCoverage;
49
    }
50
51
    public function setCodeCoverage(self $codeCoverage)
52
    {
53
        $this->codeCoverage = $codeCoverage;
0 ignored issues
show
Documentation Bug introduced by
It seems like $codeCoverage of type Doyo\Behat\Coverage\Bridge\CodeCoverage\Processor is incompatible with the declared type SebastianBergmann\CodeCoverage\CodeCoverage of property $codeCoverage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
    }
55
56
    /**
57
     * @return CodeCoverage
58
     */
59 2
    public function getCodeCoverage()
60
    {
61 2
        return $this->codeCoverage;
62
    }
63
64 2
    public function addTestCase(TestCase $testCase)
65
    {
66 2
        $this->testCases[$testCase->getName()] = $testCase;
67
    }
68
69 2
    public function complete()
70
    {
71 2
        $coverage  = $this->codeCoverage;
72 2
        $testCases = $this->testCases;
73 2
        $tests     = $coverage->getTests();
74
75 2
        foreach ($testCases as $testCase) {
76 2
            $name                   = $testCase->getName();
77 2
            $tests[$name]['status'] = $testCase->getResult();
78
        }
79
80 2
        $coverage->setTests($tests);
81 2
        $this->completed = true;
82
    }
83
84 3
    public function start(TestCase $testCase, $clear = false)
85
    {
86 3
        $this->codeCoverage->start($testCase->getName(), $clear);
87
    }
88
89 4
    public function __call($name, $arguments)
90
    {
91 4
        $codeCoverage = $this->codeCoverage;
92 4
        if (method_exists($codeCoverage, $name)) {
93 4
            return \call_user_func_array([$codeCoverage, $name], $arguments);
94
        }
95
        throw new \RuntimeException('Method name: '.$name.' not supported.');
96
    }
97
}
98