Conditions | 5 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 5.2 |
Changes | 0 |
1 | <?php |
||
18 | 5 | public static function detect($class) |
|
19 | { |
||
20 | 5 | $constants = []; |
|
21 | 5 | $reflection = new \ReflectionClass($class); |
|
22 | |||
23 | 5 | if (PHP_VERSION_ID >= 70100) { |
|
24 | // Since PHP-7.1 visibility modifiers are allowed for class constants |
||
25 | // for enumerations we are only interested in public once. |
||
26 | 5 | foreach ($reflection->getReflectionConstants() as $constant) { |
|
27 | 5 | if ($constant->isPublic()) { |
|
28 | 5 | $constants[$constant->getName()] = $constant->getValue(); |
|
29 | } |
||
30 | } |
||
31 | } else { |
||
32 | // In PHP < 7.1 all class constants were public by definition |
||
33 | foreach ($reflection->getConstants() as $constant_name => $constant_value) { |
||
34 | $constants[$constant_name] = $constant_value; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | 5 | return $constants; |
|
39 | } |
||
40 | } |
||
41 |