Passed
Pull Request — master (#13)
by
unknown
02:49
created

NestedNavigationHelper::isCurrent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
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\Nested\Registry;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\Nested\Registry 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\Nested\Builder\NavigationBuilder;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\Ne...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...
10
use Everlution\Navigation\Nested\AdvancedNavigationInterface;
0 ignored issues
show
Bug introduced by
The type Everlution\Navigation\Ne...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...
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