Completed
Push — master ( 61861a...273003 )
by Stefano
05:00
created

Enum::key()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 6
rs 9.4285
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 {
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...
14
15
  private function __construct(){}
0 ignored issues
show
introduced by
Since you have declared this class abstract, and the constructor is private, maybe you should also declare the constructor as final.
Loading history...
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