Completed
Push — master ( 094374...cc7986 )
by Eric
07:01
created

Enum::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * @author Eric Braun <[email protected]>
5
 */
6
abstract class Enum
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /** @var array */
9
    protected static $cache;
10
11
    /**
12
     * @param string|int $value
13
     *
14
     * @return bool
15
     */
16
    public static function isValid($value)
17
    {
18
        return in_array($value, static::getValues(), true);
19
    }
20
21
    /**
22
     * @return array
23
     */
24
    public static function getValues()
25
    {
26
        if (!isset(static::$cache[static::class])) {
27
            $reflection = new ReflectionClass(static::class);
28
            static::$cache[static::class] = $reflection->getConstants();
29
        }
30
31
        return static::$cache[static::class];
32
    }
33
}
34