Alias   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 23
c 0
b 0
f 0
rs 10
ccs 0
cts 16
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 0 3 1
A validate() 0 13 3
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