@@ -10,64 +10,64 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | abstract class BaseEnum { |
| 12 | 12 | |
| 13 | - private static $constCacheArray = NULL; |
|
| 13 | + private static $constCacheArray=NULL; |
|
| 14 | 14 | |
| 15 | - private static $picked = []; |
|
| 15 | + private static $picked=[]; |
|
| 16 | 16 | |
| 17 | 17 | public static function getConstants() { |
| 18 | - if (self::$constCacheArray == NULL) { |
|
| 19 | - self::$constCacheArray = []; |
|
| 18 | + if (self::$constCacheArray==NULL) { |
|
| 19 | + self::$constCacheArray=[]; |
|
| 20 | 20 | } |
| 21 | - $calledClass = get_called_class(); |
|
| 22 | - if (! \array_key_exists($calledClass, self::$constCacheArray)) { |
|
| 23 | - $reflect = new \ReflectionClass($calledClass); |
|
| 24 | - self::$constCacheArray[$calledClass] = $reflect->getConstants(); |
|
| 21 | + $calledClass=get_called_class(); |
|
| 22 | + if (!\array_key_exists($calledClass, self::$constCacheArray)) { |
|
| 23 | + $reflect=new \ReflectionClass($calledClass); |
|
| 24 | + self::$constCacheArray[$calledClass]=$reflect->getConstants(); |
|
| 25 | 25 | } |
| 26 | 26 | return self::$constCacheArray[$calledClass]; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public static function getConstantValues($postFix = "", $prefixBefore = false) { |
|
| 30 | - if ($postFix == "") |
|
| 29 | + public static function getConstantValues($postFix="", $prefixBefore=false) { |
|
| 30 | + if ($postFix=="") |
|
| 31 | 31 | return \array_values(self::getConstants()); |
| 32 | 32 | else { |
| 33 | - if ($prefixBefore === false) { |
|
| 34 | - return \array_map(function ($elem) use ($postFix) { |
|
| 35 | - return $elem . " " . $postFix; |
|
| 33 | + if ($prefixBefore===false) { |
|
| 34 | + return \array_map(function($elem) use ($postFix) { |
|
| 35 | + return $elem." ".$postFix; |
|
| 36 | 36 | }, \array_values(self::getConstants())); |
| 37 | 37 | } else { |
| 38 | - return \array_map(function ($elem) use ($postFix) { |
|
| 39 | - return $postFix . " " . $elem; |
|
| 38 | + return \array_map(function($elem) use ($postFix) { |
|
| 39 | + return $postFix." ".$elem; |
|
| 40 | 40 | }, \array_values(self::getConstants())); |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function isValidName($name, $strict = false) { |
|
| 46 | - $constants = self::getConstants(); |
|
| 45 | + public static function isValidName($name, $strict=false) { |
|
| 46 | + $constants=self::getConstants(); |
|
| 47 | 47 | |
| 48 | 48 | if ($strict) { |
| 49 | 49 | return \array_key_exists($name, $constants); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - $keys = \array_map('strtolower', array_keys($constants)); |
|
| 52 | + $keys=\array_map('strtolower', array_keys($constants)); |
|
| 53 | 53 | return \in_array(\strtolower($name), $keys); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public static function isValidValue($value) { |
| 57 | - $values = \array_values(self::getConstants()); |
|
| 57 | + $values=\array_values(self::getConstants()); |
|
| 58 | 58 | return \in_array($value, $values, true); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - public static function getRandomValue(bool $unique = false) { |
|
| 62 | - $values = self::getConstantValues(); |
|
| 63 | - $count = \count($values); |
|
| 64 | - if ($unique && $count > count(self::$picked)) { |
|
| 61 | + public static function getRandomValue(bool $unique=false) { |
|
| 62 | + $values=self::getConstantValues(); |
|
| 63 | + $count=\count($values); |
|
| 64 | + if ($unique && $count>count(self::$picked)) { |
|
| 65 | 65 | do { |
| 66 | - $newVal = $values[\rand(0, $count - 1)]; |
|
| 66 | + $newVal=$values[\rand(0, $count-1)]; |
|
| 67 | 67 | } while (isset(self::$picked[$newVal])); |
| 68 | - self::$picked[$newVal] = true; |
|
| 68 | + self::$picked[$newVal]=true; |
|
| 69 | 69 | return $newVal; |
| 70 | 70 | } |
| 71 | - return $values[\rand(0, $count - 1)]; |
|
| 71 | + return $values[\rand(0, $count-1)]; |
|
| 72 | 72 | } |
| 73 | 73 | } |
@@ -5,5 +5,5 @@ |
||
| 5 | 5 | |
| 6 | 6 | abstract class Animals extends BaseEnum { |
| 7 | 7 | |
| 8 | - const CAT = 'cat', CROW = 'crow', DOG = 'dog', DOVE = 'dove', DRAGON = 'dragon', FEATHER = 'feather', FEATHER_ALTERNATE = 'feather alternate', FISH = 'fish', FOG = 'frog', HIPPO = 'hippo', HORSE = 'horse', HORSE_HEAD = 'horse head', KIWI_BIRD = 'kiwi bird', OTTER = 'otter', PAW = 'paw', SPIDER = 'spider'; |
|
| 8 | + const CAT='cat', CROW='crow', DOG='dog', DOVE='dove', DRAGON='dragon', FEATHER='feather', FEATHER_ALTERNATE='feather alternate', FISH='fish', FOG='frog', HIPPO='hippo', HORSE='horse', HORSE_HEAD='horse head', KIWI_BIRD='kiwi bird', OTTER='otter', PAW='paw', SPIDER='spider'; |
|
| 9 | 9 | } |