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

NestedRegistryCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
A addAlias() 0 5 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\NavigationBundle\DependencyInjection\Compiler;
6
7
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...
8
use Everlution\NavigationBundle\Bridge\NavigationAliasContainer;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Definition;
12
use Symfony\Component\DependencyInjection\Reference;
13
14
/**
15
 * Class NestedRegistryCompilerPass.
16
 *
17
 * @author Martin Lutter <[email protected]>
18
 */
19
class NestedRegistryCompilerPass implements CompilerPassInterface
20
{
21
    public function process(ContainerBuilder $container)
22
    {
23
        $registry = $container->findDefinition(Registry::class);
24
        $aliasContainer = $container->findDefinition(NavigationAliasContainer::class);
25
        $services = $container->findTaggedServiceIds('everlution.advanced_navigation');
26
27
        foreach ($services as $id => $tags) {
28
            $registry->addMethodCall('addContainer', [new Reference($id)]);
29
            $this->addAlias($aliasContainer, $id, $tags);
30
        }
31
    }
32
33
    private function addAlias(Definition $container, string $id, array $tags)
34
    {
35
        foreach ($tags as $tag) {
36
            if (array_key_exists('alias', $tag)) {
37
                $container->addMethodCall('addAlias', [$tag['alias'], $id]);
38
            }
39
        }
40
    }
41
}
42