Completed
Push — develop ( e4e826...d92786 )
by ANTHONIUS
11s queued 10s
created

Compat   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 21.28%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 56
ccs 10
cts 47
cp 0.2128
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

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