Test Failed
Push — master ( 3eb0e4...9196b6 )
by Ivan
02:13
created

RootNavigationItem::addChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Everlution\Navigation;
6
7
/**
8
 * Interface Navigation.
9
 * @author Ivan Barlog <[email protected]>
10
 */
11
class RootNavigationItem implements Item
12
{
13
    /** @var string */
14
    private $identifier;
15
    /** @var string */
16
    private $label;
17
    /** @var Item[] */
18
    private $children;
19
20
    public function __construct(string $identifier, string $label = null)
21
    {
22
        $this->identifier = $identifier;
23
        $this->label = $label ?? $identifier;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getIdentifier(): string
30
    {
31
        return $this->identifier;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getLabel(): string
38
    {
39
        return $this->label;
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    public function getChildren(): array
46
    {
47
        return $this->children;
48
    }
49
50
    /**
51
     * @param Item $item
52
     * @return Item
53
     */
54
    public function addChild(Item $item)
55
    {
56
        $this->children[] = $item;
57
58
        return $this;
59
    }
60
61
    /**
62
     * @param Item $parent
63
     * @return Item
64
     * @throws \Exception
65
     */
66
    public function setParent(Item $parent)
67
    {
68
        throw new \Exception(sprintf('%s cannot have parent', self::class));
69
    }
70
71
    /**
72
     * @return Item|null
73
     */
74
    public function getParent()
75
    {
76
        return null;
77
    }
78
}
79