Failed Conditions
Push — v7 ( c80b33...0b1ec1 )
by Florent
04:39
created

HeaderCheckerCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 18 5
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Bundle\Checker\DependencyInjection\Compiler;
13
14
use Jose\Component\Checker\HeaderCheckerManagerFactory;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class HeaderCheckerCompilerPass implements CompilerPassInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function process(ContainerBuilder $container)
25
    {
26
        if (!$container->hasDefinition(HeaderCheckerManagerFactory::class)) {
27
            return;
28
        }
29
30
        $definition = $container->getDefinition(HeaderCheckerManagerFactory::class);
31
32
        $taggedHeaderCheckerServices = $container->findTaggedServiceIds('jose.checker.header');
33
        foreach ($taggedHeaderCheckerServices as $id => $tags) {
34
            foreach ($tags as $attributes) {
35
                if (!array_key_exists('alias', $attributes)) {
36
                    throw new \InvalidArgumentException(sprintf("The header checker '%s' does not have any 'alias' attribute.", $id));
37
                }
38
                $definition->addMethodCall('add', [$attributes['alias'], new Reference($id)]);
39
            }
40
        }
41
    }
42
}
43