NavigationAliasContainer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 13 3
A addAlias() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\NavigationBundle\Bridge;
6
7
/**
8
 * Class NavigationAliasContainer.
9
 *
10
 * @author Ivan Barlog <[email protected]>
11
 */
12
class NavigationAliasContainer
13
{
14
    private $container = [];
15
16
    public function addAlias(string $alias, string $class): void
17
    {
18
        $this->container[$alias] = $class;
19
    }
20
21
    /**
22
     * @param string $name
23
     *
24
     * @return string
25
     *
26
     * @throws AliasDoesNotExistException
27
     */
28
    public function get(string $name): string
29
    {
30
        if (class_exists($name)) {
31
            // we received class name instead of the alias
32
            return $name;
33
        }
34
35
        if (array_key_exists($name, $this->container)) {
36
            // alias exists returning the class name
37
            return $this->container[$name];
38
        }
39
40
        throw new AliasDoesNotExistException($name);
41
    }
42
}
43