Completed
Pull Request — master (#47)
by Wachter
07:18
created

HandlerCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 26
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 3
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * Compiler pass which collects worker services.
20
 */
21
class HandlerCompilerPass implements CompilerPassInterface
22
{
23
    const REGISTRY_ID = 'task.handler.factory';
24
25
    const HANDLER_TAG = 'task.handler';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 4
    public function process(ContainerBuilder $container)
31
    {
32 4
        if (!$container->has(self::REGISTRY_ID)) {
33
            return;
34
        }
35
36 4
        $handler = [];
37 4
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
38 4
        foreach ($taggedServices as $id => $tags) {
39 3
            $service = $container->getDefinition($id);
40 3
            $handler[$service->getClass()] = new Reference($id);
41
        }
42
43 4
        $definition = $container->findDefinition(self::REGISTRY_ID);
44 4
        $definition->replaceArgument(0, $handler);
45 4
    }
46
}
47