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

Enum   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 4 1
A getValues() 0 9 2
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