Enum::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Enum
5
 *
6
 * A simple implementation of an Enum DataType.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2015-2016 - http://caffeina.com
11
 */
12
13
abstract class Enum {
14
15
  final private function __construct(){}
16
17
  protected static function __constants(){
18
    static $_consts = null;
19
    if (null === $_consts) {
20
      $_consts = array_change_key_case(
21
        (new ReflectionClass(get_called_class()))->getConstants()
22
      , CASE_UPPER);
23
    }
24
    return $_consts;
25
  }
26
27
  public static function key($value){
28
  	foreach (static::__constants() as $key => $const_val) {
29
  		if ($const_val === $value) return $key;
30
  	}
31
  	return false;
32
  }
33
34
  public static function has($value){
35
    return isset(static::__constants()[strtoupper($value)]);
36
  }
37
38
}
39