Total Complexity | 8 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
10 | abstract class Enum extends \MyCLabs\Enum\Enum |
||
11 | { |
||
12 | protected function isFlag($flag): bool |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * @param $name |
||
19 | * @param $arguments |
||
20 | * @throws \ReflectionException |
||
21 | * @return bool |
||
22 | */ |
||
23 | public function __call($name, $arguments) |
||
24 | { |
||
25 | $array = static::toArray(); |
||
26 | $regexBase = '/(is)(%s)/m'; |
||
27 | $regexFull = sprintf($regexBase, implode('$|', array_keys($array))); |
||
28 | preg_match($regexFull, $name, $match); |
||
29 | if (count($match)>0 && $match[0] === $name) { |
||
30 | return $this->{$match[1] . 'Flag'}($array[$match[2]], $arguments[0] ?? null); |
||
31 | } |
||
32 | throw new BadMethodCallException(sprintf('Enum %s not found on %s', $name, get_class($this))); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param self ...$candidates |
||
37 | * @return bool |
||
38 | */ |
||
39 | public function isAnyOf(self ...$candidates): bool |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns the enum key (i.e. the constant name). |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getKey() |
||
59 |