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

HandlerCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 54.55%

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 6
cts 11
cp 0.5455
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 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