Completed
Push — master ( 83d554...edb865 )
by Alexander
06:18 queued 04:13
created

Annotation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parseValues() 0 11 4
A getName() 0 4 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