Passed
Push — master ( 83d554...edb865 )
by Alexander
04:11
created

Annotation::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Flying\Struct\Annotation;
4
5
use Doctrine\Common\Annotations\AnnotationException;
6
7
/**
8
 * Base class for structure annotations
9
 */
10
abstract class Annotation
11
{
12
    /**
13
     * Name of structure property
14
     *
15
     * @var string
16
     */
17
    private $name;
18
19
    /**
20
     * Class constructor
21
     *
22
     * @param array $values
23
     * @throws AnnotationException
24
     */
25 190
    public function __construct(array $values)
26
    {
27 190
        $this->parseValues($values);
28 187
    }
29
30
    /**
31
     * Parse given annotation values
32
     *
33
     * @param array $values
34
     * @throws AnnotationException
35
     * @return void
36
     */
37 190
    protected function parseValues(array &$values)
38
    {
39 190
        if (array_key_exists('name', $values)) {
40 189
            $this->name = $values['name'];
41 189
            unset($values['name']);
42 189
        }
43
        // Check if we got required properties
44 190
        if ((!is_string($this->name)) || ($this->name === '')) {
45 1
            throw new AnnotationException('Required property annotation is missed: name');
46
        }
47 189
    }
48
49
    /**
50
     * Get structure property name
51
     *
52
     * @return string
53
     */
54 180
    public function getName()
55
    {
56 180
        return $this->name;
57
    }
58
}
59