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

Enum::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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