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

NavigationContainer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNavigationContainers() 0 3 1
A get() 0 7 2
A add() 0 3 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
    public function get(string $name): NestableContainerInterface
32
    {
33
        if (false === isset($this->containers[$name])) {
34
            throw new ContainerNotFoundException();
35
        }
36
37
        return $this->containers[$name];
38
    }
39
40
    abstract public function getRoot(): ContainerInterface;
41
}
42