Passed
Pull Request — develop (#5)
by ANTHONIUS
10:30
created

Compat::getCoverageValidConfigs()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 14.7187

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 4
nop 0
dl 0
loc 26
ccs 3
cts 24
cp 0.125
crap 14.7187
rs 9.6333
c 0
b 0
f 0
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 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 getVersion()
36
    {
37
        static $version;
38
        if (null === $version) {
39
            $version = Version::id();
40
        }
41
42 8
        return $version;
43
    }
44 8
45 8
    public static function getCoverageValidConfigs()
46 1
    {
47
        $r       = new \ReflectionClass(CodeCoverage::class);
48
        $configs = [];
49 8
        $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