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

Enum   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
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
/**
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