Completed
Push — master ( cc7986...ecd0e8 )
by Eric
09:41
created

Enum::getValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace Oqq\Minc\Common;
4
5
/**
6
 * @author Eric Braun <[email protected]>
7
 */
8
abstract class Enum
9
{
10
    /** @var array */
11
    protected static $cache;
12
13
    /**
14
     * @param string|int $value
15
     *
16
     * @return bool
17
     */
18
    public static function isValid($value)
19
    {
20
        return in_array($value, static::getValues(), true);
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public static function getValues()
27
    {
28
        if (!isset(static::$cache[static::class])) {
29
            $reflection = new \ReflectionClass(static::class);
30
            static::$cache[static::class] = $reflection->getConstants();
31
        }
32
33
        return static::$cache[static::class];
34
    }
35
}
36