Failed Conditions
Push — master ( d9377e...587e80 )
by Florent
02:05
created

KeySetControllerCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
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
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\KeyManagement\DependencyInjection\Compiler;
15
16
use Jose\Bundle\KeyManagement\Routing\JWKSetLoader;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * Class KeySetControllerCompilerPass.
23
 */
24
final class KeySetControllerCompilerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition(JWKSetLoader::class)) {
32
            return;
33
        }
34
35
        $definition = $container->getDefinition(JWKSetLoader::class);
36
37
        $taggedAlgorithmServices = $container->findTaggedServiceIds('jose.key_set.controller');
38
        foreach ($taggedAlgorithmServices as $id => $tags) {
39
            foreach ($tags as $attributes) {
40
                if (!array_key_exists('path', $attributes)) {
41
                    throw new \InvalidArgumentException(sprintf("The algorithm '%s' does not have any 'alias' attribute.", $id));
42
                }
43
                $definition->addMethodCall('add', [$attributes['path'], $id]);
44
            }
45
        }
46
    }
47
}
48