InjectEventDispatcherPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 3
eloc 9
c 3
b 0
f 1
nc 3
nop 1
dl 0
loc 13
ccs 0
cts 12
cp 0
crap 12
rs 9.9666
1
<?php
2
3
namespace OldSound\RabbitMqBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Class InjectEventDispatcherPass
12
 *
13
 * @package OldSound\RabbitMqBundle\DependencyInjection\Compiler
14
 */
15
class InjectEventDispatcherPass implements CompilerPassInterface
16
{
17
    const EVENT_DISPATCHER_SERVICE_ID = 'event_dispatcher';
18
19
    /**
20
     * @inheritDoc
21
     */
22
    public function process(ContainerBuilder $container)
23
    {
24
        if (!$container->has(self::EVENT_DISPATCHER_SERVICE_ID)) {
25
            return;
26
        }
27
        $taggedConsumers = $container->findTaggedServiceIds('old_sound_rabbit_mq.base_amqp');
28
29
        foreach ($taggedConsumers as $id => $tag) {
30
            $definition = $container->getDefinition($id);
31
            $definition->addMethodCall(
32
                'setEventDispatcher',
33
                array(
34
                    new Reference(self::EVENT_DISPATCHER_SERVICE_ID, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)
35
                )
36
            );
37
        }
38
39
    }
40
}
41