Completed
Push — master ( 8a5d0f...f400e4 )
by Wachter
23:12
created

HandlerCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 29
ccs 13
cts 14
cp 0.9286
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 4
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
    const HANDLER_NAME_ATTRIBUTE = 'handler-name';
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 36
    public function process(ContainerBuilder $container)
25
    {
26 36
        if (!$container->has(self::REGISTRY_ID)) {
27
            return;
28
        }
29
30 36
        $definition = $container->findDefinition(self::REGISTRY_ID);
31
32 36
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
33 36
        foreach ($taggedServices as $id => $tags) {
34 36
            foreach ($tags as $attributes) {
35 36
                $definition->addMethodCall(
36 36
                    self::ADD_FUNCTION_NAME,
37 36
                    [$attributes[self::HANDLER_NAME_ATTRIBUTE], new Reference($id)]
38 24
                );
39 24
            }
40 24
        }
41 36
    }
42
}
43