Alias::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
c 0
b 0
f 0
rs 10
ccs 0
cts 12
cp 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * Created by gerk on 19.09.16 09:46
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Annotation\Slumber;
7
8
use Doctrine\Common\Annotations\Annotation;
9
use PeekAndPoke\Component\Slumber\Annotation\SlumberAnnotation;
10
use PeekAndPoke\Component\Slumber\Core\Validation\ValidationContext;
11
12
13
/**
14
 * Use this annotation to give a class an alias.
15
 *
16
 * The can be useful for polymorphics.
17
 *
18
 * It will also be picked up by libraries like Rip.
19
 *
20
 * @Annotation
21
 * @Annotation\Target("CLASS")
22
 *
23
 * @author Karsten J. Gerber <[email protected]>
24
 */
25
class Alias extends SlumberAnnotation
26
{
27
    /**
28
     * @return string
29
     */
30
    public function getAlias()
31
    {
32
        return (string) $this->value;
33
    }
34
35
    public function validate(ValidationContext $context)
36
    {
37
        if (empty($this->value)) {
38
            throw $this->createValidationException(
39
                $context,
40
                'The type alias must not have an empty value.'
41
            );
42
        }
43
44
        if (! \is_string($this->value)) {
0 ignored issues
show
introduced by
The condition is_string($this->value) is always true.
Loading history...
45
            throw $this->createValidationException(
46
                $context,
47
                'The type alias must be a string'
48
            );
49
        }
50
    }
51
}
52