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

Registry::getContainer()   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\ContainerAlreadyRegisteredException;
6
use Everlution\Navigation\ContainerIsNotRegisteredException;
7
8
/**
9
 * Class AdvancedRegistry
10
 * @author Martin Lutter <[email protected]>
11
 */
12
class Registry
13
{
14
    /** @var AdvancedNavigationInterface[] */
15
    private $containers = [];
16
17
    public function addContainer(AdvancedNavigationInterface $container)
18
    {
19
        $containerName = get_class($container);
20
        if (array_key_exists($containerName, $this->containers)) {
21
            throw new ContainerAlreadyRegisteredException($containerName);
22
        }
23
24
        $this->containers[$containerName] = $container;
25
    }
26
27
    public function getContainer(string $containerName): AdvancedNavigationInterface
28
    {
29
        if (false === array_key_exists($containerName, $this->containers)) {
30
            throw new ContainerIsNotRegisteredException($containerName);
31
        }
32
33
        return $this->containers[$containerName];
34
    }
35
}
36