Processor   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 127
rs 10
c 0
b 0
f 0
wmc 17

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setCodeCoverageOptions() 0 3 1
A __construct() 0 4 1
A setCodeCoverage() 0 3 1
A getCurrentTestCase() 0 3 1
A merge() 0 7 2
A getCodeCoverage() 0 8 2
A stop() 0 3 1
A getCodeCoverageFilter() 0 3 1
A getCodeCoverageOptions() 0 3 1
A addTestCase() 0 3 1
A start() 0 5 1
A setCurrentTestCase() 0 3 1
A complete() 0 13 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 <[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\Bridge\CodeCoverage;
15
16
use SebastianBergmann\CodeCoverage\CodeCoverage;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\CodeCoverage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\Driver\Driver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use SebastianBergmann\CodeCoverage\Filter;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\Filter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
    public function __construct($driver = null, $filter = null)
58
    {
59
        $this->driver = $driver;
60
        $this->filter = $filter;
61
    }
62
63
    public function setCurrentTestCase(TestCase $testCase)
64
    {
65
        $this->currentTestCase = $testCase;
66
    }
67
68
    public function getCurrentTestCase()
69
    {
70
        return $this->currentTestCase;
71
    }
72
73
    public function setCodeCoverageOptions(array $options)
74
    {
75
        $this->coverageOptions = $options;
76
    }
77
78
    public function getCodeCoverageOptions()
79
    {
80
        return $this->coverageOptions;
81
    }
82
83
    public function getCodeCoverageFilter()
84
    {
85
        return $this->filter;
86
    }
87
88
    public function start(TestCase $testCase, $clear = false)
89
    {
90
        $this->setCurrentTestCase($testCase);
91
        $this->addTestCase($testCase);
92
        $this->getCodeCoverage()->start($testCase->getName(), $clear);
93
    }
94
95
    public function stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false): array
96
    {
97
        return $this->getCodeCoverage()->stop($append, $linesToBeCovered, $linesToBeUsed, $ignoreForceCoversAnnotation);
98
    }
99
100
    public function merge($processor)
101
    {
102
        $codeCoverage = $processor;
103
        if ($processor instanceof self) {
104
            $codeCoverage = $processor->getCodeCoverage();
105
        }
106
        $this->getCodeCoverage()->merge($codeCoverage);
107
    }
108
109
    public function clear()
110
    {
111
        $this->getCodeCoverage()->clear();
112
    }
113
114
    public function setCodeCoverage(CodeCoverage $codeCoverage)
115
    {
116
        $this->codeCoverage = $codeCoverage;
117
    }
118
119
    /**
120
     * @return CodeCoverage
121
     */
122
    public function getCodeCoverage()
123
    {
124
        if (null === $this->codeCoverage) {
125
            $this->codeCoverage = new CodeCoverage($this->driver, $this->filter);
126
            $this->codeCoverage->setDisableIgnoredLines(true);
127
        }
128
129
        return $this->codeCoverage;
130
    }
131
132
    public function addTestCase(TestCase $testCase)
133
    {
134
        $this->testCases[$testCase->getName()] = $testCase;
135
    }
136
137
    public function complete()
138
    {
139
        $coverage  = $this->getCodeCoverage();
140
        $testCases = $this->testCases;
141
        $tests     = $coverage->getTests();
142
143
        foreach ($testCases as $testCase) {
144
            $name                   = $testCase->getName();
145
            $tests[$name]['status'] = $testCase->getResult();
146
        }
147
148
        $coverage->setTests($tests);
149
        $this->completed = true;
150
    }
151
}
152