| Total Complexity | 13 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Coverage | 96.15% |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | abstract class Enum |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @return Generator<int|string> |
||
| 23 | */ |
||
| 24 | 4 | final public static function getIterator(): Generator |
|
| 36 | } |
||
| 37 | 2 | } |
|
| 38 | |||
| 39 | 4 | final public static function has(string $key): bool |
|
| 40 | { |
||
| 41 | 4 | foreach (static::getIterator() as $keyConst => $valueConst) { |
|
| 42 | 4 | if ($key !== $keyConst) { |
|
| 43 | 4 | continue; |
|
| 44 | } |
||
| 45 | |||
| 46 | 4 | return true; |
|
| 47 | } |
||
| 48 | |||
| 49 | 2 | return false; |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param int|string $value |
||
| 54 | */ |
||
| 55 | 4 | final public static function isValid($value): bool |
|
| 56 | { |
||
| 57 | 4 | foreach (static::getIterator() as $valueConst) { |
|
| 58 | 4 | if ($value !== $valueConst) { |
|
| 59 | 4 | continue; |
|
| 60 | } |
||
| 61 | |||
| 62 | 4 | return true; |
|
| 63 | } |
||
| 64 | |||
| 65 | 1 | return false; |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param int|string $value |
||
| 70 | * |
||
| 71 | * @throws Exception |
||
| 72 | */ |
||
| 73 | 3 | final public static function key($value): string |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return int|string |
||
| 86 | */ |
||
| 87 | 4 | final public static function value(string $value) |
|
| 90 | } |
||
| 91 | } |
||
| 92 |