ExpectationCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 4
1
<?php
2
3
namespace Overwatch\ExpectationBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * ExpectationCompilerPass
11
 * Finds all services tagged with EXPECTATION_TAG (i.e. all expection classes)
12
 * and notifies the EXPECTATION_MANAGER of their existance.
13
 */
14
class ExpectationCompilerPass implements CompilerPassInterface
15
{
16
    const EXPECTATION_MANAGER = 'overwatch_expectation.expectation_manager';
17
    const EXPECTATION_TAG = 'overwatch_expectation.expectation';
18
19
    public function process(ContainerBuilder $container)
20
    {
21
        if (!$container->hasDefinition(self::EXPECTATION_MANAGER)) {
22
            return;
23
        }
24
25
        $definition = $container->getDefinition(self::EXPECTATION_MANAGER);
26
27
        $taggedServices = $container->findTaggedServiceIds(self::EXPECTATION_TAG);
28
29
        foreach ($taggedServices as $id => $tags) {
30
            foreach ($tags as $attributes) {
31
                $definition->addMethodCall(
32
                    'add',
33
                    [new Reference($id), $attributes['alias']]
34
                );
35
            }
36
        }
37
    }
38
}
39