Passed
Pull Request — master (#6)
by
unknown
02:08
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\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