Passed
Pull Request — master (#5)
by Ivan
01:48
created

RootNode::addChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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