RegisterFlushersPass::process()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 14
cts 14
cp 1
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 13
nc 7
nop 1
crap 5
1
<?php
2
3
namespace TreeHouse\QueueBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\DefinitionDecorator;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class RegisterFlushersPass implements CompilerPassInterface
11
{
12
    /**
13
     * @inheritdoc
14
     */
15 4
    public function process(ContainerBuilder $container)
16
    {
17 4
        if (!$container->hasDefinition('tree_house.queue.event_listener.flush')) {
18 1
            return;
19
        }
20
21 3
        $listener = $container->getDefinition('tree_house.queue.event_listener.flush');
22
23 3
        foreach (['doctrine', 'doctrine_mongodb'] as $id) {
24 3
            if ($container->hasDefinition($id)) {
25 2
                $flusherId = sprintf('tree_house.queue.flusher.%s', $id);
26
27 2
                $definition = new DefinitionDecorator('tree_house.queue.flusher.doctrine_abstract');
28 2
                $definition->addArgument(new Reference($id));
29 2
                $container->setDefinition($flusherId, $definition);
30
31 3
                $listener->addMethodCall('addFlusher', [new Reference($flusherId)]);
32
            }
33
        }
34
35 3
        foreach ($container->findTaggedServiceIds('tree_house.queue.flusher') as $id => list($tag)) {
36 1
            $listener->addMethodCall('addFlusher', [new Reference($id)]);
37
        }
38 3
    }
39
}
40