Failed Conditions
Push — master ( ea06df...34d59f )
by Florent
10:18
created

DataCollectorServicesCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 13
nc 3
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\Bundle\JoseFramework\DataCollector\JoseCollector;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
/**
23
 * Class DataCollectorServicesCompilerPass.
24
 */
25
final class DataCollectorServicesCompilerPass implements CompilerPassInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function process(ContainerBuilder $container)
31
    {
32
        if (!$container->hasDefinition(JoseCollector::class)) {
33
            return;
34
        }
35
36
        $definition = $container->getDefinition(JoseCollector::class);
37
38
        $services = [
39
            'addJWSBuilder' => 'jose.jws_builder',
40
            'addJWSVerifier' => 'jose.jws_verifier',
41
            'addJWEBuilder' => 'jose.jwe_builder',
42
            'addJWEDecrypter' => 'jose.jwe_decrypter',
43
            'addJWK' => 'jose.jwk',
44
            'addJWKSet' => 'jose.jwkset',
45
        ];
46
        foreach ($services as $method => $tag) {
47
            $this->collectServices($method, $tag, $definition, $container);
48
        }
49
    }
50
51
    /**
52
     * @param string           $method
53
     * @param string           $tag
54
     * @param Definition       $definition
55
     * @param ContainerBuilder $container
56
     */
57
    private function collectServices(string $method, string $tag, Definition $definition, ContainerBuilder $container)
58
    {
59
        $taggedAlgorithmServices = $container->findTaggedServiceIds($tag);
60
        foreach ($taggedAlgorithmServices as $id => $tags) {
61
            $definition->addMethodCall($method, [$id, new Reference($id)]);
62
        }
63
    }
64
}
65