RootNode::addChild()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation\Builder;
6
7
use Everlution\Navigation\MutableContainer;
8
use Everlution\Navigation\Helper\ItemHelper;
9
10
/**
11
 * Class RootNode.
12
 *
13
 * @author Ivan Barlog <[email protected]>
14
 */
15
class RootNode
16
{
17
    /** @var ParentNode[] */
18
    private $children = [];
19
20
    public function addChild(ParentNode $item): void
21
    {
22
        $this->children[ItemHelper::getIdentifier($item->getItem())] = $item;
23
    }
24
25
    public function hasChildren(): bool
26
    {
27
        return false === empty($this->children);
28
    }
29
30
    /**
31
     * @return ParentNode[]
32
     */
33
    public function getChildren(): array
34
    {
35
        return $this->children;
36
    }
37
38
    public function setChildren(array $children)
39
    {
40
        $this->children = $children;
41
    }
42
43
    public function has(string $name): bool
44
    {
45
        return array_key_exists($name, $this->children);
46
    }
47
48
    public function get(string $name): ParentNode
49
    {
50
        return $this->children[$name];
51
    }
52
}
53