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

Registry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addContainer() 0 8 2
A getContainer() 0 7 2
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