LoadRabbitMQConfigPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 5
c 4
b 2
f 0
lcom 0
cbo 2
dl 0
loc 49
ccs 33
cts 33
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 46 5
1
<?php
2
3
namespace Innmind\ProvisionerBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
8
/**
9
 * Extract RabbitMQ config from "old sound" bundle services
10
 * and inject them in the rabbitmq admin object
11
 */
12
class LoadRabbitMQConfigPass implements CompilerPassInterface
13
{
14 3
    public function process(ContainerBuilder $container)
15
    {
16 3
        $admin = $container->getDefinition('innmind_provisioner.rabbitmq.admin');
17 3
        $consumers = $container->findTaggedServiceIds(
18
            'old_sound_rabbit_mq.consumer'
19 3
        );
20
21 3
        foreach ($consumers as $id => $tags) {
22 3
            $def = $container->getDefinition($id);
23
24 3
            foreach ($def->getMethodCalls() as $call) {
25 3
                if ($call[0] === 'setQueueOptions') {
26 3
                    $queue = $call[1][0]['name'];
27 3
                    break;
28
                }
29 3
            }
30
31 3
            if (!isset($queue)) {
32 3
                continue;
33
            }
34
35 3
            $connectionId = (string) $def->getArgument(0);
36 3
            $def = $container->getDefinition($connectionId);
37
38 3
            $host = $def->getArgument(0);
39 3
            $port = $def->getArgument(1);
40 3
            $user = $def->getArgument(2);
41 3
            $pwd = $def->getArgument(3);
42 3
            $vhost = $def->getArgument(4);
43
44 3
            $admin->addMethodCall(
45 3
                'setConsumerDefinition',
46
                [
47 3
                    substr($id, 20, -9),
48 3
                    $queue,
49 3
                    $host,
50 3
                    $port,
51 3
                    $user,
52 3
                    $pwd,
53 3
                    $vhost,
54
                ]
55 3
            );
56
57 3
            unset($queue);
58 3
        }
59 3
    }
60
}
61