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

NavigationContainer::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Everlution\Navigation\Nested;
4
5
use Everlution\Navigation\ContainerInterface;
6
use Everlution\Navigation\Nested\Container\ContainerNotFoundException;
7
use Everlution\Navigation\Nested\Container\NestableContainerInterface;
8
9
/**
10
 * Class NavigationContainer
11
 * @author Martin Lutter <[email protected]>
12
 */
13
abstract class NavigationContainer implements AdvancedNavigationInterface
14
{
15
    /** @var \Everlution\Navigation\Nested\Container\NestableContainerInterface[] */
16
    private $containers = [];
17
18
    public function add(NestableContainerInterface $container): void
19
    {
20
        $this->containers[get_class($container)] = $container;
21
    }
22
23
    /**
24
     * @return \Everlution\Navigation\ContainerInterface[]
25
     */
26
    public function getNavigationContainers(): array
27
    {
28
        return $this->containers;
29
    }
30
31
    /**
32
     * @param string $name
33
     * @return NestableContainerInterface
34
     * @throws ContainerNotFoundException
35
     */
36
    public function get(string $name): NestableContainerInterface
37
    {
38
        if (false === isset($this->containers[$name])) {
39
            throw new ContainerNotFoundException($name);
40
        }
41
42
        return $this->containers[$name];
43
    }
44
45
    /**
46
     * @return ContainerInterface
47
     */
48
    abstract public function getRoot(): ContainerInterface;
49
}
50