ContainerAwareCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 4
1
<?php
2
3
namespace BenTools\ContainerAwareBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ContainerAwareCompilerPass implements CompilerPassInterface
10
{
11
12
    /**
13
     * @inheritDoc
14
     */
15
    public function process(ContainerBuilder $container)
16
    {
17
        foreach ($container->getServiceIds() as $serviceId) {
18
            $definition = $container->findDefinition($serviceId);
19
            $class = $definition->getClass();
20
            if (is_a($class, 'Symfony\Component\DependencyInjection\ContainerAwareInterface', true)) {
21
                if (!$definition->hasMethodCall('setContainer')) {
22
                    $definition->addMethodCall('setContainer', array(new Reference('service_container')));
23
                }
24
            }
25
        }
26
    }
27
}
28