Passed
Pull Request — master (#12)
by
unknown
06:01
created

AdvancedNavigationHelper::getNavigation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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\ContainerRegistry;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\ContainerRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Everlution\Navigation\ContainerBuilder\ContainerMatcherInterface;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\Co...ntainerMatcherInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Everlution\Navigation\ContainerBuilder\NavigationBuilder;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\Co...ilder\NavigationBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Everlution\Navigation\ContainerBuilder\AdvancedNavigationInterface;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\Co...ncedNavigationInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Everlution\Navigation\Item\ItemInterface;
13
use Everlution\Navigation\Url\CannotProvideUrlForItemException;
14
use Everlution\Navigation\Url\UrlProviderContainer;
15
use Everlution\NavigationBundle\Bridge\Item\TranslatableItemLabelInterface;
16
use Everlution\NavigationBundle\Bridge\NavigationAliasContainer;
17
use Symfony\Component\Translation\TranslatorInterface;
18
19
/**
20
 * Class AdvancedNavigationHelper
21
 *
22
 * @author Martin Lutter <[email protected]>
23
 */
24
class AdvancedNavigationHelper
25
{
26
    /** @var ContainerRegistry */
27
    private $registry;
28
    /** @var NavigationAliasContainer */
29
    private $aliasContainer;
30
    /** @var MatcherInterface */
31
    private $matcher;
32
    /** @var NavigationBuilder[] */
33
    private $container = [];
34
35
    public function __construct(
36
        ContainerRegistry $registry,
37
        NavigationAliasContainer $aliasContainer,
38
        MatcherInterface $matcher
39
    ) {
40
        $this->registry = $registry;
41
        $this->aliasContainer = $aliasContainer;
42
        $this->matcher = $matcher;
43
    }
44
45
    public function isCurrent(ItemInterface $item): bool
46
    {
47
        return $this->matcher->isCurrent($item);
48
    }
49
50
    public function getNavigation(string $navigation): NavigationBuilder
51
    {
52
        if (false === array_key_exists($navigation, $this->container)) {
53
            $container = $this->getContainer($navigation);
54
            $this->container[$navigation] = new NavigationBuilder($container, $this->matcher);
55
        }
56
57
        return $this->container[$navigation];
58
    }
59
60
    private function getContainer(string $navigation): AdvancedNavigationInterface
61
    {
62
        return $this->registry->getContainer($this->aliasContainer->get($navigation));
63
    }
64
}
65