| Total Complexity | 5 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class AsEnum extends PropertyMappingMarkerBase |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @param ValidationContext $context |
||
| 23 | * |
||
| 24 | * @throws SlumberException |
||
| 25 | */ |
||
| 26 | public function validate(ValidationContext $context) |
||
| 27 | { |
||
| 28 | if (empty($this->value)) { |
||
| 29 | throw $this->createValidationException( |
||
| 30 | $context, |
||
| 31 | 'you must provide a class as value. Example @Slumber\AsObject( MyEnum::class )' |
||
| 32 | ); |
||
| 33 | } |
||
| 34 | |||
| 35 | if (!class_exists($this->value)) { |
||
| 36 | throw $this->createValidationException( |
||
| 37 | $context, |
||
| 38 | "you provided the non-existing class '$this->value'" |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (!is_a($this->value, Enumerated::class, true)) { |
||
| 43 | throw $this->createValidationException( |
||
| 44 | $context, |
||
| 45 | "you provided the class '$this->value' which does not extend " . Enumerated::class |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return bool |
||
| 52 | */ |
||
| 53 | public function keepNullValuesInCollections() |
||
| 56 | } |
||
| 57 | } |
||
| 58 |