Completed
Push — master ( 57cdbf...61c19f )
by Peter
03:19
created

ConstantDetector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 36.36%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 28
ccs 4
cts 11
cp 0.3636
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A detect() 0 20 4
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2017, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Enum;
12
13
class ConstantDetector
14
{
15
    /**
16
     * @param string $class
17
     *
18
     * @return array
19
     */
20 3
    public static function detect($class)
21
    {
22 3
        $reflection = new \ReflectionClass($class);
23
24 3
        if (PHP_VERSION_ID >= 70100) {
25
            // Since PHP-7.1 visibility modifiers are allowed for class constants
26
            // for enumerations we are only interested in public once.
27
            $constants = [];
28
            foreach ($reflection->getReflectionConstants() as $constant) {
29
                if ($constant->isPublic()) {
30
                    $constants[$constant->getName()] = $constant->getValue();
31
                }
32
            }
33
34
            return $constants;
35
        }
36
37
        // In PHP < 7.1 all class constants were public by definition
38 3
        return $reflection->getConstants();
39
    }
40
}
41