Completed
Push — master ( c2e487...7ac6a5 )
by Wachter
07:39
created

HandlerCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.0058

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 13
cts 14
cp 0.9286
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 4.0058
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 2
    public function process(ContainerBuilder $container)
24
    {
25 2
        if (!$container->has(self::REGISTRY_ID)) {
26
            return;
27
        }
28
29 2
        $definition = $container->findDefinition(self::REGISTRY_ID);
30
31 2
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
32 2
        foreach ($taggedServices as $id => $tags) {
33 1
            foreach ($tags as $attributes) {
34 1
                $definition->addMethodCall(
35 1
                    self::ADD_FUNCTION_NAME,
36 1
                    [$attributes['name'], new Reference($id)]
37 1
                );
38 1
            }
39 2
        }
40 2
    }
41
}
42