ClaimCheckerCompilerPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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 InvalidArgumentException;
17
use Jose\Bundle\JoseFramework\Services\ClaimCheckerManagerFactory;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
final class ClaimCheckerCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @throws InvalidArgumentException if the claim checker has no alias
28
     */
29
    public function process(ContainerBuilder $container): void
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 (!isset($attributes['alias'])) {
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