StrategyCompilerPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 33
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 30 6
1
<?php
2
3
/*
4
 * This file is part of the Conveyor package.
5
 *
6
 * (c) Jeroen Fiege <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webcreate\Conveyor\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * Pass to add tagged strategies to the StrategyFactory
19
 *
20
 */
21
class StrategyCompilerPass implements CompilerPassInterface
22
{
23 3
    public function process(ContainerBuilder $container)
24
    {
25 3
        if (!$container->hasDefinition('strategy.factory')) {
26
            return;
27
        }
28
29 3
        $definition = $container->getDefinition('strategy.factory');
30 3
        $taggedServices = $container->findTaggedServiceIds('strategy');
31
32 3
        foreach ($taggedServices as $id => $tagsAttributes) {
33 3
            foreach ($tagsAttributes as $attributes) {
34
                $attributes += array(
35 3
                    'alias'         => $id,
36
                    'configuration' => false,
37
                );
38
39 3
                if ($attributes['configuration']) {
40 3
                    $ref = new \ReflectionClass($attributes['configuration']);
41 3
                    if (!$ref->implementsInterface('Symfony\Component\Config\Definition\ConfigurationInterface')) {
42
                        throw new \Exception(sprintf('The tag attribute "configuration" for service "%s" must implement "Symfony\Component\Config\Definition\ConfigurationInterface"', $id));
43
                    }
44
                }
45
46 3
                $definition->addMethodCall(
47 3
                    'addStrategy',
48 3
                    array($id, $attributes['alias'], $attributes['configuration'])
49
                );
50
            }
51
        }
52 3
    }
53
}
54