Completed
Push — master ( 19fab1...ec2cfc )
by ANTHONIUS
23s queued 11s
created

Processor   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 96
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCurrentTestCase() 0 3 1
A getCodeCoverage() 0 3 1
A stop() 0 3 1
A addTestCase() 0 3 1
A start() 0 5 1
A complete() 0 13 2
A setCurrentTestCase() 0 3 1
A merge() 0 7 2
A clear() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
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\Bridge\CodeCoverage;
15
16
use SebastianBergmann\CodeCoverage\CodeCoverage;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Doyo\Bridge\CodeCoverage\CodeCoverage. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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;
0 ignored issues
show
introduced by
The private property $driver is not used, and could be removed.
Loading history...
41
42
    /**
43
     * @var Filter
44
     */
45
    private $filter;
0 ignored issues
show
introduced by
The private property $filter is not used, and could be removed.
Loading history...
46
47
    /**
48
     * @var TestCase
49
     */
50
    private $currentTestCase;
51
52 22
    public function __construct(CodeCoverage $codeCoverage)
53
    {
54 22
        $this->codeCoverage = $codeCoverage;
55
    }
56
57 7
    public function setCurrentTestCase(TestCase $testCase)
58
    {
59 7
        $this->currentTestCase = $testCase;
60
    }
61
62 116
    public function getCurrentTestCase()
63
    {
64 116
        return $this->currentTestCase;
65
    }
66
67 6
    public function start(TestCase $testCase, $clear = false)
68
    {
69 6
        $this->setCurrentTestCase($testCase);
70 6
        $this->addTestCase($testCase);
71 5
        $this->codeCoverage->start($testCase->getName(), $clear);
72
    }
73
74 116
    public function stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false): array
75
    {
76 116
        return $this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed, $ignoreForceCoversAnnotation);
77
    }
78
79 1
    public function merge($processor)
80
    {
81 1
        $codeCoverage = $processor;
82 1
        if ($processor instanceof self) {
83 1
            $codeCoverage = $processor->getCodeCoverage();
84
        }
85 1
        $this->getCodeCoverage()->merge($codeCoverage);
86
    }
87
88 3
    public function clear()
89
    {
90 3
        $this->codeCoverage->clear();
91
    }
92
93
    /**
94
     * @return CodeCoverage
95
     */
96 4
    public function getCodeCoverage()
97
    {
98 4
        return $this->codeCoverage;
99
    }
100
101 7
    public function addTestCase(TestCase $testCase)
102
    {
103 7
        $this->testCases[$testCase->getName()] = $testCase;
104
    }
105
106 2
    public function complete()
107
    {
108 2
        $coverage  = $this->codeCoverage;
109 2
        $testCases = $this->testCases;
110 2
        $tests     = $coverage->getTests();
111
112 2
        foreach ($testCases as $testCase) {
113 2
            $name                   = $testCase->getName();
114 2
            $tests[$name]['status'] = $testCase->getResult();
115
        }
116
117 2
        $coverage->setTests($tests);
118 2
        $this->completed = true;
119
    }
120
}
121