Completed
Pull Request — master (#290)
by Leny
08:38
created

ViewReferenceBuilderCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 23 5
1
<?php
2
3
namespace Victoire\Bundle\ViewReferenceBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Class ViewReferenceBuilderCompilerPass.
12
 */
13
class ViewReferenceBuilderCompilerPass implements CompilerPassInterface
14
{
15
    public function process(ContainerBuilder $container)
16
    {
17
        if (!$container->hasDefinition('victoire_view_reference.builder_chain')) {
18
            return;
19
        }
20
        $definition = $container->getDefinition(
21
            'victoire_view_reference.builder_chain'
22
        );
23
        $taggedServices = $container->findTaggedServiceIds(
24
            'victoire_view_reference.view_reference.builder'
25
        );
26
        foreach ($taggedServices as $id => $tagAttributes) {
27
            foreach ($tagAttributes as $attributes) {
28
                if (!array_key_exists('view', $attributes)) {
29
                    throw new InvalidConfigurationException('View class attribute is not defined for '.$id);
30
                }
31
                $definition->addMethodCall(
32
                    'addViewReferenceBuilder',
33
                    [new Reference($id), $attributes['view']]
34
                );
35
            }
36
        }
37
    }
38
}
39