Failed Conditions
Push — master ( 58ba10...7c4f18 )
by Florent
06:41 queued 04:14
created

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