Conditions | 7 |
Paths | 14 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
39 | public function __construct(array $values) |
||
40 | { |
||
41 | if ( ! isset($values['literal'])) { |
||
42 | $values['literal'] = []; |
||
43 | } |
||
44 | |||
45 | foreach ($values['value'] as $var) { |
||
46 | if( ! is_scalar($var)) { |
||
47 | throw new \InvalidArgumentException(sprintf( |
||
48 | '@Enum supports only scalar values "%s" given.', |
||
49 | is_object($var) ? get_class($var) : gettype($var) |
||
50 | )); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | foreach ($values['literal'] as $key => $var) { |
||
55 | if( ! in_array($key, $values['value'])) { |
||
56 | throw new \InvalidArgumentException(sprintf( |
||
57 | 'Undefined enumerator value "%s" for literal "%s".', |
||
58 | $key , $var |
||
59 | )); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | $this->value = $values['value']; |
||
64 | $this->literal = $values['literal']; |
||
65 | } |
||
67 |