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

Registry::addContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Everlution\Navigation\Nested;
4
5
use Everlution\Navigation\Nested\AdvancedNavigationInterface;
6
use Everlution\Navigation\ContainerAlreadyRegisteredException;
7
use Everlution\Navigation\ContainerIsNotRegisteredException;
8
9
/**
10
 * Class AdvancedRegistry
11
 * @author Martin Lutter <[email protected]>
12
 */
13
class Registry
14
{
15
    /** @var AdvancedNavigationInterface[] */
16
    private $containers = [];
17
18
    public function addContainer(AdvancedNavigationInterface $container)
19
    {
20
        $containerName = get_class($container);
21
        if (array_key_exists($containerName, $this->containers)) {
22
            throw new ContainerAlreadyRegisteredException($containerName);
23
        }
24
25
        $this->containers[$containerName] = $container;
26
    }
27
28
    public function getContainer(string $containerName): AdvancedNavigationInterface
29
    {
30
        if (false === array_key_exists($containerName, $this->containers)) {
31
            throw new ContainerIsNotRegisteredException($containerName);
32
        }
33
34
        return $this->containers[$containerName];
35
    }
36
}
37