ResultReporterCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Overwatch\ResultBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * ResultReporterCompilerPass
11
 * Finds all services tagged with REPORTER_TAG (i.e. all ResultReporter classes)
12
 * and notifies the REPORTER_MANAGER of their existance.
13
 */
14
class ResultReporterCompilerPass implements CompilerPassInterface
15
{
16
    const RESULT_REPORTER_MANAGER = 'overwatch_result.result_reporter_manager';
17
18
    const RESULT_REPORTER_TAG = 'overwatch_result.result_reporter';
19
20
    public function process(ContainerBuilder $container)
21
    {
22
        if (!$container->hasDefinition(self::RESULT_REPORTER_MANAGER)) {
23
            return;
24
        }
25
26
        $definition = $container->getDefinition(self::RESULT_REPORTER_MANAGER);
27
        $taggedServices = $container->findTaggedServiceIds(self::RESULT_REPORTER_TAG);
28
29
        foreach ($taggedServices as $id => $tags) {
30
            $definition->addMethodCall(
31
                'add',
32
                [new Reference($id)]
33
            );
34
        }
35
    }
36
}
37