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

HeaderCheckerCompilerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 1
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