HappyrMq2phpExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 52
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B load() 0 32 2
A requireBundle() 0 7 2
1
<?php
2
3
namespace Happyr\Mq2phpBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
use Symfony\Component\DependencyInjection\Loader;
9
10
/**
11
 * This is the class that loads and manages your bundle configuration.
12
 *
13
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
14
 */
15
class HappyrMq2phpExtension extends Extension
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    public function load(array $configs, ContainerBuilder $container)
21
    {
22 2
        $configuration = new Configuration();
23 2
        $config = $this->processConfiguration($configuration, $configs);
24
25 2
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26 2
        $loader->load('services.yml');
27
28 2
        $this->requireBundle('SimpleBusAsynchronousBundle', $container);
29
30
        // Add the command and event queue names to the consumer wrapper
31 2
        $def = $container->getDefinition('happyr.mq2php.consumer_wrapper');
32 2
        $def->replaceArgument(0, $config['command_queue'])
33 2
            ->replaceArgument(1, $config['event_queue']);
34
35 2
        $container->setParameter('happyr.mq2php.command_queue_name', $config['command_queue']);
36 2
        $container->setParameter('happyr.mq2php.event_queue_name', $config['event_queue']);
37
38 2
        $serializerId = 'happyr.mq2php.message_serializer';
39 2
        if (!$config['enabled']) {
40
            $container->removeDefinition($serializerId);
41
42
            return;
43
        }
44
45
        // Add default headers to the serializer
46 2
        $def = $container->getDefinition($serializerId);
47 2
        $def->replaceArgument(2, $config['message_headers']);
48
49
        // Add the secret key as parameter
50 2
        $container->setParameter('happyr.mq2php.secret_key', $config['secret_key']);
51 2
    }
52
53
    /**
54
     * Make sure we have activated the required bundles.
55
     *
56
     * @param $bundleName
57
     * @param ContainerBuilder $container
58
     */
59 2
    private function requireBundle($bundleName, ContainerBuilder $container)
60
    {
61 2
        $enabledBundles = $container->getParameter('kernel.bundles');
62 2
        if (!isset($enabledBundles[$bundleName])) {
63
            throw new \LogicException(sprintf('You need to enable "%s" as well', $bundleName));
64
        }
65 2
    }
66
}
67