Completed
Push — master ( 58e792...f01f49 )
by Matthew
05:34
created

DtcQueueExtension::load()   C

Complexity

Conditions 12
Paths 25

Size

Total Lines 42
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 16.1951

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 18
cts 26
cp 0.6923
rs 5.1612
c 0
b 0
f 0
cc 12
eloc 25
nc 25
nop 2
crap 16.1951

How to fix   Complexity   

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
3
namespace Dtc\QueueBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Processor;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
use Symfony\Component\Config\FileLocator;
9
use Symfony\Component\DependencyInjection\Loader;
10
11
class DtcQueueExtension extends Extension
12
{
13 1
    public function load(array $configs, ContainerBuilder $container)
14
    {
15 1
        $processor = new Processor();
16 1
        $configuration = new Configuration();
17
18 1
        $config = $processor->processConfiguration($configuration, $configs);
19
20 1
        if (isset($config['beanstalkd'])) {
21
            if (!isset($config['beanstalkd']['host'])) {
22
                throw new \Exception('dtc_queue: beanstalkd requires host in config.yml');
23
            }
24
        }
25
26 1
        if (isset($config['beanstalkd']['host'])) {
27
            $container->setParameter('dtc_queue.beanstalkd.host', $config['beanstalkd']['host']);
28
        }
29 1
        if (isset($config['beanstalkd']['tube'])) {
30
            $container->setParameter('dtc_queue.beanstalkd.tube', $config['beanstalkd']['tube']);
31
        }
32
33 1
        if (isset($config['rabbit_mq'])) {
34
            foreach (['host', 'port', 'user', 'password'] as $value) {
35
                if (!isset($config['rabbit_mq'][$value])) {
36
                    throw new \Exception('dtc_queue: rabbit_mq must have '.$value.' in config.yml');
37
                }
38
            }
39
            $container->setParameter('dtc_queue.rabbit_mq', $config['rabbit_mq']);
40
        }
41
42 1
        $container->setParameter('dtc_queue.default_manager', $config['default_manager']);
43 1
        $container->setParameter('dtc_queue.document_manager', $config['document_manager']);
44 1
        $container->setParameter('dtc_queue.entity_manager', $config['entity_manager']);
45 1
        $container->setParameter('dtc_queue.class_job', isset($config['class_job']) ? $config['class_job'] : null);
46 1
        $container->setParameter('dtc_queue.class_job_archive', isset($config['class_job_archive']) ? $config['class_job_archive'] : null);
47 1
        $container->setParameter('dtc_queue.class_run', isset($config['class_run']) ? $config['class_run'] : null);
48 1
        $container->setParameter('dtc_queue.class_run_archive', isset($config['class_run_archive']) ? $config['class_run_archive'] : null);
49
50
        // Load Grid if Dtc\GridBundle Bundle is registered
51 1
        $yamlLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
52
53 1
        $yamlLoader->load('queue.yml');
54 1
    }
55
56
    public function getAlias()
57
    {
58
        return 'dtc_queue';
59
    }
60
}
61