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

HandlerCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 28
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
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