Passed
Pull Request — develop (#5)
by ANTHONIUS
04:29
created

Compat   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 23.81%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 49
ccs 10
cts 42
cp 0.2381
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverClass() 0 9 2
A getVersion() 0 8 2
A getCoverageValidConfigs() 0 26 4
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension 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\Behat\Coverage\Bridge;
15
16
use SebastianBergmann\CodeCoverage\CodeCoverage;
17
use SebastianBergmann\CodeCoverage\Version;
18
19
/**
20
 * Utility class to load driver by php-code-coverage version.
21
 */
22
class Compat
23
{
24 10
    public static function getDriverClass($name)
25
    {
26 10
        $namespace = 'Doyo\\Behat\\Coverage\\Bridge\\Driver\\';
27 10
        if (version_compare(static::getVersion(), '6.0', '<')) {
28
            $namespace = $namespace.'Compat\\';
29
        }
30 10
        $class = $namespace.$name;
31
32 10
        return $class;
33
    }
34
35 10
    public static function getVersion()
36
    {
37 10
        static $version;
38 10
        if (null === $version) {
39 1
            $version = Version::id();
40
        }
41
42 10
        return $version;
43
    }
44
45
    public static function getCoverageValidConfigs()
46
    {
47
        $r       = new \ReflectionClass(CodeCoverage::class);
48
        $configs = [];
49
        $ignored = [
50
            'data',
51
            'tests',
52
            'cachetokens',
53
            'maptestclassnametocoveredclassname',
54
        ];
55
        foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
56
            $methodName = $method->getName();
57
            if (false === strpos($methodName, 'set')) {
58
                continue;
59
            }
60
            $configName = substr($methodName, 3);
61
            $lower      = strtolower($configName);
62
            if (\in_array($lower, $ignored, true)) {
63
                continue;
64
            }
65
            $defaults             = $r->getDefaultProperties();
66
            $configName           = lcfirst($configName);
67
            $configs[$configName] = $defaults[$configName];
68
        }
69
70
        return $configs;
71
    }
72
}
73