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