Completed
Pull Request — master (#15)
by Wachter
06:01
created

HandlerCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 0
cbo 3
dl 0
loc 25
ccs 11
cts 12
cp 0.9167
rs 10

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
    const HANDLER_TAG = 'task.handler';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 12
    public function process(ContainerBuilder $container)
30
    {
31 12
        if (!$container->has(self::REGISTRY_ID)) {
32
            return;
33
        }
34
35 12
        $handler = [];
36 12
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
37 12
        foreach ($taggedServices as $id => $tags) {
38 12
            $service = $container->getDefinition($id);
39 12
            $handler[$service->getClass()] = new Reference($id);
40 8
        }
41
42 12
        $definition = $container->findDefinition(self::REGISTRY_ID);
43 12
        $definition->replaceArgument(0, $handler);
44 12
    }
45
}
46