Passed
Pull Request — master (#6)
by
unknown
01:41
created

ContainerRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addContainer() 0 8 2
A getContainer() 0 7 2
1
<?php
2
3
namespace Everlution\Navigation;
4
5
use Everlution\Navigation\ContainerBuilder\AdvancedNavigationInterface;
6
7
/**
8
 * Class ContainerRegistry
9
 * @author Martin Lutter <[email protected]>
10
 */
11
class ContainerRegistry
12
{
13
    /** @var AdvancedNavigationInterface[] */
14
    private $containers = [];
15
16
    public function addContainer(AdvancedNavigationInterface $container)
17
    {
18
        $containerName = get_class($container);
19
        if (array_key_exists($containerName, $this->containers)) {
20
            throw new ContainerAlreadyRegisteredException($containerName);
21
        }
22
23
        $this->containers[$containerName] = $container;
24
    }
25
26
    public function getContainer(string $containerName): AdvancedNavigationInterface
27
    {
28
        if (false === array_key_exists($containerName, $this->containers)) {
29
            throw new ContainerIsNotRegisteredException($containerName);
30
        }
31
32
        return $this->containers[$containerName];
33
    }
34
}
35