| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | ); |
||
| 58 |