Completed
Push — master ( 91afcf...c2e487 )
by Wachter
05:08
created

HandlerCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.5022

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 6
cts 11
cp 0.5455
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 5.5022
1
<?php
2
3
namespace Task\TaskBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Compiler pass which collects worker services.
11
 *
12
 * @author @wachterjohannes <[email protected]>
13
 */
14
class HandlerCompilerPass implements CompilerPassInterface
15
{
16
    const REGISTRY_ID = 'task.handler_registry';
17
    const HANDLER_TAG = 'task.handler';
18
    const ADD_FUNCTION_NAME = 'add';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 1
    public function process(ContainerBuilder $container)
24
    {
25 1
        if (!$container->has(self::REGISTRY_ID)) {
26
            return;
27
        }
28
29 1
        $definition = $container->findDefinition(self::REGISTRY_ID);
30
31 1
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
32 1
        foreach ($taggedServices as $id => $tags) {
33
            foreach ($tags as $attributes) {
34
                $definition->addMethodCall(
35
                    self::ADD_FUNCTION_NAME,
36
                    [$attributes['name'], new Reference($id)]
37
                );
38
            }
39
        }
40 1
    }
41
}
42