CustomProviderPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 30 4
1
<?php
2
3
namespace DoS\QueueBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class CustomProviderPass implements CompilerPassInterface
10
{
11
    /**
12
     * @inheritDoc
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        if (!$container->hasParameter('uecode_qpush.provider.custom')) {
17
            return;
18
        }
19
20
        $configs = $container->getExtensionConfig('uecode_qpush');
21
22
        foreach($configs[0]['queues'] as $queue => $value) {
23
            $definition = clone $container->getDefinition('dos.queue.provider.doctrine_orm');
24
            $definition->replaceArgument(0, $queue);
25
            $definition->replaceArgument(1, $value['options']);
26
27
            if ($container->hasDefinition('event_dispatcher')) {
28
                $definition->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher')));
29
            } else {
30
                $definition->addMethodCall('setEventDispatcher', array(new Reference('debug.event_dispatcher')));
31
            }
32
33
            $container->getDefinition('uecode_qpush.'. $queue)->replaceArgument(2, $definition);
34
            $container->setDefinition(sprintf('uecode_qpush.%s', $queue), $definition)
35
                ->addTag('monolog.logger', ['channel' => 'qpush'])
36
                ->addTag('kernel.event_listener', array(
37
                    'event' => "kernel.terminate",
38
                    'method' => "onKernelTerminate",
39
                    'priority' => 255
40
                ))
41
            ;
42
        }
43
    }
44
}
45