| Total Complexity | 6 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 45.45% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class ClassEnum |
||
| 15 | { |
||
| 16 | public const INTERNET = 1; |
||
| 17 | public const CSNET = 2; |
||
| 18 | public const CHAOS = 3; |
||
| 19 | public const HESIOD = 4; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | public static $classes = [ |
||
| 25 | self::INTERNET => 'IN', |
||
| 26 | self::CSNET => 'CS', |
||
| 27 | self::CHAOS => 'CHAOS', |
||
| 28 | self::HESIOD => 'HS', |
||
| 29 | ]; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Determine if a class is valid. |
||
| 33 | * |
||
| 34 | * @param string $class |
||
| 35 | * |
||
| 36 | * @return bool |
||
| 37 | */ |
||
| 38 | public static function isValid($class): bool |
||
| 39 | { |
||
| 40 | return array_key_exists($class, self::$classes); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param int $class |
||
| 45 | * |
||
| 46 | * @return mixed |
||
| 47 | * |
||
| 48 | * @throws \InvalidArgumentException |
||
| 49 | */ |
||
| 50 | public static function getName(int $class): string |
||
| 51 | { |
||
| 52 | if (!static::isValid($class)) { |
||
| 53 | throw new \InvalidArgumentException(sprintf('No class matching integer "%s"', $class)); |
||
| 54 | } |
||
| 55 | |||
| 56 | return self::$classes[$class]; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $name |
||
| 61 | * |
||
| 62 | * @return int |
||
| 63 | */ |
||
| 64 | 43 | public static function getClassFromName(string $name): int |
|
| 73 | } |
||
| 74 | } |
||
| 75 |