Completed
Push — develop ( feab1b...eba14b )
by Baptiste
03:55
created

InnmindAMQPExtension::load()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 52
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 32
CRAP Score 5.0006

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 32
cts 33
cp 0.9697
rs 8.6868
c 0
b 0
f 0
cc 5
eloc 33
nc 16
nop 2
crap 5.0006

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQPBundle\DependencyInjection;
5
6
use Symfony\Component\{
7
    HttpKernel\DependencyInjection\Extension,
8
    DependencyInjection\ContainerBuilder,
9
    DependencyInjection\Loader,
10
    DependencyInjection\Reference,
11
    Config\FileLocator
12
};
13
14
final class InnmindAMQPExtension extends Extension
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 4
    public function load(array $configs, ContainerBuilder $container)
20
    {
21 4
        $loader = new Loader\YamlFileLoader(
22 4
            $container,
23 4
            new FileLocator(__DIR__.'/../Resources/config')
24
        );
25 4
        $loader->load('services.yml');
26 4
        $config = $this->processConfiguration(
27 4
            new Configuration,
28 4
            $configs
29
        );
30
31
        $container
32 4
            ->getDefinition('innmind.amqp.connection.default')
33 4
            ->replaceArgument(1, $config['server'])
34 4
            ->replaceArgument(3, $config['server']['timeout'])
35 4
            ->replaceArgument(4, new Reference($config['clock']));
36
37 4
        $definition = $container->getDefinition('innmind.amqp.argument_translator');
38
39 4
        foreach ($config['argument_translators'] as $translator) {
40
            $definition->addArgument(new Reference($translator));
41
        }
42
43 4
        $autoDeclare = $container->getDefinition('innmind.amqp.client.auto_declare');
44 4
        $consumers = $container->getDefinition('innmind.amqp.consumers');
45
46 4
        foreach ($config['exchanges'] as $name => $exchange) {
47 4
            $autoDeclare->addMethodCall(
48 4
                'declareExchange',
49 4
                [$name, $exchange['type'], $exchange['durable'], $exchange['arguments']]
50
            );
51
        }
52
53 4
        foreach ($config['queues'] as $name => $queue) {
54 4
            $autoDeclare->addMethodCall(
55 4
                'declareQueue',
56 4
                [$name, $queue['durable'], $queue['exclusive'], $queue['arguments']]
57
            );
58 4
            $consumers->addMethodCall(
59 4
                'add',
60 4
                [$name, new Reference($queue['consumer'])]
61
            );
62
        }
63
64 4
        foreach ($config['bindings'] as $binding) {
65 4
            $autoDeclare->addMethodCall(
66 4
                'declareBinding',
67 4
                [$binding['exchange'], $binding['queue'], $binding['routingKey'], $binding['arguments']]
68
            );
69
        }
70 4
    }
71
}
72