OverrideRoutingCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 20 3
1
<?php
2
3
namespace Zenstruck\ObjectRoutingBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Alias;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * @author Christophe Coevoet <[email protected]>
11
 * @author Francis Besset <[email protected]>
12
 * @author Benjamin Eberlei <[email protected]>
13
 * @author Kevin Bond <[email protected]>
14
 *
15
 * @see https://github.com/BeSimple/BeSimpleI18nRoutingBundle
16
 */
17
class OverrideRoutingCompilerPass implements CompilerPassInterface
18
{
19 4
    public function process(ContainerBuilder $container)
20
    {
21 4
        if (!$container->hasDefinition('zenstruck_object_routing.router')) {
22 1
            return;
23
        }
24
25 3
        if ($container->hasAlias('router')) {
26
            // router is an alias.
27
            // Register a private alias for this service to inject it as the parent
28 2
            $container->setAlias('zenstruck_object_routing.router.parent', new Alias((string) $container->getAlias('router'), false));
29
        } else {
30
            // router is a definition.
31
            // Register it again as a private service to inject it as the parent
32 1
            $definition = $container->getDefinition('router');
33 1
            $definition->setPublic(false);
34 1
            $container->setDefinition('zenstruck_object_routing.router.parent', $definition);
35
        }
36
37 3
        $container->setAlias('router', 'zenstruck_object_routing.router');
38 3
    }
39
}
40