Passed
Branch master (baa65a)
by Oliver
09:35
created

ConfigLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadConfig() 0 30 6
1
<?php
2
3
namespace OckCyp\CoversValidator\Loader;
4
5
use OckCyp\CoversValidator\Model\ConfigurationHolder;
6
use PHPUnit\Util\Configuration;
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 ConfigLoader
9
{
10
    /**
11
     * Load configuration from file
12
     *
13
     * @param string $fileName
14
     * @return ConfigurationHolder
15
     */
16
    public static function loadConfig(string $fileName): ConfigurationHolder
17
    {
18
        if (class_exists(Configuration::class)) {
19
            // @codeCoverageIgnoreStart
20
            $configuration = Configuration::getInstance($fileName);
21
            $filename = $configuration->getFilename();
22
            $phpunit = $configuration->getPHPUnitConfiguration();
23
            $bootstrap = '';
24
            if (isset($phpunit['bootstrap'])) {
25
                $bootstrap = $phpunit['bootstrap'];
26
            }
27
            // @codeCoverageIgnoreEnd
28
        } else {
29
            if (class_exists('PHPUnit\TextUI\Configuration\Loader', true)) {
30
                // PHPUnit < 9.3
31
                $loader = new \PHPUnit\TextUI\Configuration\Loader();
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...
32
            } elseif (class_exists('PHPUnit\TextUI\XmlConfiguration\Loader', true)) {
33
                // PHPUnit >= 9.3
34
                $loader = new \PHPUnit\TextUI\XmlConfiguration\Loader();
35
            } else {
36
                throw new \RuntimeException('Could not find PHPUnit configuration loader class');
37
            }
38
39
            $configuration = $loader->load($fileName);
40
            $filename = $configuration->filename();
41
            $phpunit = $configuration->phpunit();
42
            $bootstrap = $phpunit->hasBootstrap() ? $phpunit->bootstrap() : null;
43
        }
44
45
        return new ConfigurationHolder($configuration, $filename, $bootstrap);
46
    }
47
}
48