Passed
Push — master ( 1fd91b...909177 )
by Ivan
01:58
created

NavigationContainer::getNavigationContainers()   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;
6
7
use Everlution\Navigation\ContainerInterface;
8
use Everlution\Navigation\Nested\Container\ContainerNotFoundException;
9
use Everlution\Navigation\Nested\Container\NestableContainerInterface;
10
11
/**
12
 * Class NavigationContainer.
13
 *
14
 * @author Martin Lutter <[email protected]>
15
 */
16
abstract class NavigationContainer implements AdvancedNavigationInterface
17
{
18
    /** @var NestableContainerInterface[] */
19
    private $containers = [];
20
21
    public function add(NestableContainerInterface $container): void
22
    {
23
        $this->containers[get_class($container)] = $container;
24
    }
25
26
    /**
27
     * @return ContainerInterface[]
28
     */
29
    public function getNavigationContainers(): array
30
    {
31
        return $this->containers;
32
    }
33
34
    /**
35
     * @param string $name
36
     *
37
     * @return NestableContainerInterface
38
     *
39
     * @throws ContainerNotFoundException
40
     */
41
    public function get(string $name): NestableContainerInterface
42
    {
43
        if (false === isset($this->containers[$name])) {
44
            throw new ContainerNotFoundException($name);
45
        }
46
47
        return $this->containers[$name];
48
    }
49
}
50