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