doyolabs /
code-coverage-bridge
| 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
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
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // 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
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. 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
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. 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 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths