Completed
Push — master ( 065363...35d2f6 )
by Wachter
28:04 queued 25:44
created

HandlerCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 12
cp 0.9167
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 1
crap 3.0052
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 17
    public function process(ContainerBuilder $container)
30
    {
31 17
        if (!$container->has(self::REGISTRY_ID)) {
32
            return;
33
        }
34
35 17
        $handler = [];
36 17
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
37 17
        foreach ($taggedServices as $id => $tags) {
38 16
            $service = $container->getDefinition($id);
39 16
            $handler[$service->getClass()] = new Reference($id);
40 17
        }
41
42 17
        $definition = $container->findDefinition(self::REGISTRY_ID);
43 17
        $definition->replaceArgument(0, $handler);
44 17
    }
45
}
46