Passed
Pull Request — master (#6)
by
unknown
02:08
created

ParentNode::getChildren()   A

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 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation\Nested\Builder;
6
7
use Everlution\Navigation\ContainerInterface;
8
9
/**
10
 * Class RootNode
11
 *
12
 * @author Martin Lutter <[email protected]>
13
 */
14
class ParentNode
15
{
16
    /** @var ContainerInterface */
17
    protected $container;
18
    /** @var ParentNode[] */
19
    protected $children = [];
20
21
    public function __construct(ContainerInterface $navigation)
22
    {
23
        $this->container = $navigation;
24
    }
25
26
    /**
27
     * @return ContainerInterface
28
     */
29
    public function getContainer(): ContainerInterface
30
    {
31
        return $this->container;
32
    }
33
34
    /**
35
     * @param ParentNode $item
36
     */
37
    public function addChild(ParentNode $item): void
38
    {
39
        $this->children[get_class($item->getContainer())] = $item;
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    public function hasChildren(): bool
46
    {
47
        return false === empty($this->children);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getChildren(): array
54
    {
55
        return $this->children;
56
    }
57
58
    /**
59
     * @param string $name
60
     * @return bool
61
     */
62
    public function has(string $name): bool
63
    {
64
        return array_key_exists($name, $this->children);
65
    }
66
67
    /**
68
     * @param string $name
69
     * @return ParentNode
70
     */
71
    public function get(string $name): ParentNode
72
    {
73
        return $this->children[$name];
74
    }
75
}
76