Passed
Push — master ( e45f2e...f88aec )
by Oliver
01:46
created

TestCollection::__construct()   B

Complexity

Conditions 8
Paths 14

Size

Total Lines 42
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 8
eloc 23
c 3
b 0
f 0
nc 14
nop 1
dl 0
loc 42
rs 8.4444
1
<?php
2
3
namespace OckCyp\CoversValidator\Model;
4
5
use PHPUnit\Runner\Version;
6
use PHPUnit\Util\Configuration as PHPUnit8Configuration;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Util\Configuration 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...
7
8
class TestCollection implements \Iterator
9
{
10
    /**
11
     * @var \Iterator
12
     */
13
    private $iterator;
14
15
    /**
16
     * @var \Iterator
17
     */
18
    private $iteratorIterator;
19
20
    public function __construct(ConfigurationHolder $configurationHolder)
21
    {
22
        $configuration = $configurationHolder->getConfiguration();
23
24
        // @codeCoverageIgnoreStart
25
        if ((int) Version::series() < 10) {
26
            if ($configuration instanceof PHPUnit8Configuration) {
27
                $this->iterator = $configuration->getTestSuiteConfiguration();
0 ignored issues
show
Bug introduced by
The method getTestSuiteConfiguration() does not exist on PHPUnit\TextUI\XmlConfiguration\Configuration. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
                /** @scrutinizer ignore-call */ 
28
                $this->iterator = $configuration->getTestSuiteConfiguration();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
            } elseif (class_exists('PHPUnit\TextUI\Configuration\TestSuiteMapper')) {
29
                // PHPUnit < 9.3
30
                $testSuiteMapper = new \PHPUnit\TextUI\Configuration\TestSuiteMapper();
0 ignored issues
show
Bug introduced by
The type PHPUnit\TextUI\Configuration\TestSuiteMapper 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...
31
                $this->iterator = $testSuiteMapper->map($configuration->testSuite(), '');
32
            } elseif (class_exists('PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper')) {
33
                // PHPUnit 9.3, 9.4
34
                $testSuiteMapper = new \PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper();
0 ignored issues
show
Bug introduced by
The type PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper 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...
35
                $this->iterator = $testSuiteMapper->map($configuration->testSuite(), '');
36
            } elseif (class_exists('PHPUnit\TextUI\TestSuiteMapper')) {
37
                // PHPUnit 9.5, 9.6
38
                $testSuiteMapper = new \PHPUnit\TextUI\TestSuiteMapper();
39
                $this->iterator = $testSuiteMapper->map($configuration->testSuite(), '');
0 ignored issues
show
Documentation Bug introduced by
It seems like $testSuiteMapper->map($c...ation->testSuite(), '') of type PHPUnit\Framework\TestSuite is incompatible with the declared type Iterator of property $iterator.

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...
40
            }
41
        // @codeCoverageIgnoreEnd
42
        } else {
43
            // PHPUnit >= 10.0: same name as PHPUnit 9.3, but map() takes different args.
44
            if (class_exists('PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper')) {
45
                $testSuiteMapper = new \PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper();
46
47
                // TestSuiteMapper eventually calls TestBuilder->configureTestCase,
48
                // which requires the ConfigurationRegistry singleton to be populated.
49
                \PHPUnit\TextUI\Configuration\Registry::init(
0 ignored issues
show
Bug introduced by
The type PHPUnit\TextUI\Configuration\Registry 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...
50
                    (new \PHPUnit\TextUI\CliArguments\Builder())->fromParameters([]),
0 ignored issues
show
Bug introduced by
The call to PHPUnit\TextUI\CliArgume...ilder::fromParameters() has too few arguments starting with additionalLongOptions. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
                    (new \PHPUnit\TextUI\CliArguments\Builder())->/** @scrutinizer ignore-call */ fromParameters([]),

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
51
                    $configuration
52
                );
53
                $this->iterator = $testSuiteMapper->map($configurationHolder->getFilename(), $configuration->testSuite(), '', '');
54
            }
55
        }
56
57
        if (!$this->iterator) {
58
            throw new \RuntimeException('Could not find PHPUnit TestSuiteMapper class'); // @codeCoverageIgnore
59
        }
60
61
        $this->iteratorIterator = new \RecursiveIteratorIterator($this->iterator);
62
    }
63
64
    #[\ReturnTypeWillChange]
65
    public function current()
66
    {
67
        return $this->iteratorIterator->current();
68
    }
69
70
    #[\ReturnTypeWillChange]
71
    public function key()
72
    {
73
        return $this->iteratorIterator->key();
74
    }
75
76
    public function next(): void
77
    {
78
        $this->iteratorIterator->next();
79
    }
80
81
    public function rewind(): void
82
    {
83
        $this->iteratorIterator->rewind();
84
    }
85
86
    public function valid(): bool
87
    {
88
        return $this->iteratorIterator->valid();
89
    }
90
91
    public function isEmpty(): bool
92
    {
93
        return !\count($this->iterator);
0 ignored issues
show
Bug introduced by
$this->iterator of type Iterator is incompatible with the type Countable|array expected by parameter $value of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
        return !\count(/** @scrutinizer ignore-type */ $this->iterator);
Loading history...
94
    }
95
}
96