AsObject   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 31
c 0
b 0
f 0
rs 10
ccs 6
cts 12
cp 0.5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A keepNullValuesInCollections() 0 3 1
A validate() 0 14 4
1
<?php
2
/**
3
 * File was created 30.09.2015 07:52
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Annotation\Slumber;
7
8
use Doctrine\Common\Annotations\Annotation;
9
use PeekAndPoke\Component\Slumber\Core\Exception\SlumberException;
10
use PeekAndPoke\Component\Slumber\Core\Validation\ValidationContext;
11
12
/**
13
 * @Annotation
14
 * @Annotation\Target("PROPERTY")
15
 *
16
 * @author Karsten J. Gerber <[email protected]>
17
 */
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()
47
    {
48 3
        return false;
49
    }
50
}
51