Passed
Push — master ( 183080...7e1c8f )
by Ivan
02:35
created

NestedNavigationHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getNavigation() 0 8 2
A isCurrent() 0 3 1
A __construct() 0 8 1
A getContainer() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\NavigationBundle\Twig;
6
7
use Everlution\Navigation\Builder\MatcherInterface;
8
use Everlution\Navigation\Nested\Registry;
9
use Everlution\Navigation\Nested\Builder\NavigationBuilder;
10
use Everlution\Navigation\Nested\AdvancedNavigationInterface;
11
use Everlution\Navigation\Item\ItemInterface;
12
use Everlution\NavigationBundle\Bridge\NavigationAliasContainer;
13
14
/**
15
 * Class NestedNavigationHelper.
16
 *
17
 * @author Martin Lutter <[email protected]>
18
 */
19
class NestedNavigationHelper
20
{
21
    /** @var Registry */
22
    private $registry;
23
    /** @var NavigationAliasContainer */
24
    private $aliasContainer;
25
    /** @var MatcherInterface */
26
    private $matcher;
27
    /** @var NavigationBuilder[] */
28
    private $container = [];
29
30
    public function __construct(
31
        Registry $registry,
32
        NavigationAliasContainer $aliasContainer,
33
        MatcherInterface $matcher
34
    ) {
35
        $this->registry = $registry;
36
        $this->aliasContainer = $aliasContainer;
37
        $this->matcher = $matcher;
38
    }
39
40
    public function isCurrent(ItemInterface $item): bool
41
    {
42
        return $this->matcher->isCurrent($item);
43
    }
44
45
    public function getNavigation(string $navigation): NavigationBuilder
46
    {
47
        if (false === array_key_exists($navigation, $this->container)) {
48
            $container = $this->getContainer($navigation);
49
            $this->container[$navigation] = new NavigationBuilder($container, $this->matcher);
50
        }
51
52
        return $this->container[$navigation];
53
    }
54
55
    private function getContainer(string $navigation): AdvancedNavigationInterface
56
    {
57
        return $this->registry->getContainer($this->aliasContainer->get($navigation));
58
    }
59
}
60