Total Complexity | 10 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
8 | final class Enum implements MappingStrategy, DefaultAttributesProvider |
||
9 | { |
||
10 | 9 | public static function hydrate(&$value, array $attributes = []): void |
|
29 | } |
||
30 | |||
31 | 5 | public static function extract(&$value, array $attributes = []): void |
|
32 | { |
||
33 | 5 | if ($value instanceof \Igni\Storage\Enum) { |
|
34 | 2 | $value = $value->getValue(); |
|
35 | 2 | return; |
|
36 | } |
||
37 | |||
38 | 3 | $values = $attributes['values']; |
|
39 | |||
40 | 3 | if (!is_array($values)) { |
|
41 | 1 | throw MappingException::forInvalidAttributeValue('values', $values, 'Is not valid class name or available value list.'); |
|
42 | } |
||
43 | |||
44 | 2 | $value = array_search($value, $attributes['values']); |
|
45 | 2 | } |
|
46 | |||
47 | 1 | public static function getDefaultAttributes(): array |
|
51 | ]; |
||
52 | } |
||
54 |