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

ConfigLoader::loadConfig()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 19
c 0
b 0
f 0
nc 7
nop 1
dl 0
loc 31
rs 8.8333
1
<?php
2
3
namespace OckCyp\CoversValidator\Loader;
4
5
use OckCyp\CoversValidator\Model\ConfigurationHolder;
6
use PHPUnit\Runner\Version;
7
use PHPUnit\TextUI\Configuration\Loader as PHPUnit9ConfigurationLoader;
0 ignored issues
show
Bug introduced by
The type PHPUnit\TextUI\Configuration\Loader 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...
8
use PHPUnit\TextUI\XmlConfiguration\Loader as PHPUnit10ConfigurationLoader;
9
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...
10
11
class ConfigLoader
12
{
13
    /**
14
     * Load configuration from file
15
     */
16
    public static function loadConfig(string $fileName): ConfigurationHolder
17
    {
18
        if ((int) Version::series() <= 8 && class_exists(PHPUnit8Configuration::class)) {
19
            // @codeCoverageIgnoreStart
20
            // PHPUnit 8.x
21
            $configuration = PHPUnit8Configuration::getInstance($fileName);
22
            $filename = $configuration->getFilename();
23
            $phpunit = $configuration->getPHPUnitConfiguration();
24
            $bootstrap = '';
25
            if (isset($phpunit['bootstrap'])) {
26
                $bootstrap = $phpunit['bootstrap'];
27
            }
28
        } else {
29
            if (class_exists(PHPUnit9ConfigurationLoader::class)) {
30
                // PHPUnit < 9.3
31
                $loader = new PHPUnit9ConfigurationLoader();
32
            // @codeCoverageIgnoreEnd
33
            } elseif (class_exists(PHPUnit10ConfigurationLoader::class)) {
34
                // PHPUnit >= 9.3
35
                $loader = new PHPUnit10ConfigurationLoader();
36
            } else {
37
                throw new \RuntimeException('Could not find PHPUnit configuration loader class'); // @codeCoverageIgnore
38
            }
39
40
            $configuration = $loader->load($fileName);
41
            $filename = $configuration->filename();
42
            $phpunit = $configuration->phpunit();
43
            $bootstrap = $phpunit->hasBootstrap() ? $phpunit->bootstrap() : null;
44
        }
45
46
        return new ConfigurationHolder($configuration, $filename, $bootstrap);
47
    }
48
}
49