InjectEventDispatcherPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 17
ccs 0
cts 7
cp 0
rs 10
c 3
b 0
f 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 3
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