InjectEventDispatcherPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 3
b 0
f 1
nc 3
nop 1
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 12
rs 10
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
    public const EVENT_DISPATCHER_SERVICE_ID = 'event_dispatcher';
18
19
    public function process(ContainerBuilder $container): void
20
    {
21
        if (!$container->has(self::EVENT_DISPATCHER_SERVICE_ID)) {
22
            return;
23
        }
24
        $taggedConsumers = $container->findTaggedServiceIds('old_sound_rabbit_mq.base_amqp');
25
26
        foreach ($taggedConsumers as $id => $tag) {
27
            $definition = $container->getDefinition($id);
28
            $definition->addMethodCall(
29
                'setEventDispatcher',
30
                [
31
                    new Reference(self::EVENT_DISPATCHER_SERVICE_ID, ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
32
                ]
33
            );
34
        }
35
    }
36
}
37