Total Complexity | 5 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Coverage | 50% |
Changes | 0 |
1 | <?php |
||
18 | class AsObject extends PropertyMappingMarkerBase |
||
19 | { |
||
20 | /** |
||
21 | * @param ValidationContext $context |
||
22 | * |
||
23 | * @throws SlumberException |
||
24 | */ |
||
25 | 6 | public function validate(ValidationContext $context) |
|
26 | { |
||
27 | 6 | if (empty($this->value)) { |
|
28 | throw $this->createValidationException( |
||
29 | $context, |
||
30 | 'you must provide a class as value. Example @Slumber\AsObject( SomeClass::class )' |
||
31 | ); |
||
32 | } |
||
33 | |||
34 | // NOTICE: we also accept interfaces here, as the interface can define a Slumber\Polymorphic |
||
35 | 6 | if (! class_exists($this->value) && ! interface_exists($this->value)) { |
|
36 | throw $this->createValidationException( |
||
37 | $context, |
||
38 | "you provided the non-existing class '$this->value'" |
||
39 | ); |
||
40 | } |
||
41 | 6 | } |
|
42 | |||
43 | /** |
||
44 | * @return bool |
||
45 | */ |
||
46 | 3 | public function keepNullValuesInCollections() |
|
49 | } |
||
50 | } |
||
51 |