JWSCollectorCompilerPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 3
A collectServices() 0 7 2
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 Jose\Bundle\JoseFramework\DataCollector\JWSCollector;
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
final class JWSCollectorCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function process(ContainerBuilder $container): void
28
    {
29
        if (!$container->hasDefinition(JWSCollector::class)) {
30
            return;
31
        }
32
33
        $definition = $container->getDefinition(JWSCollector::class);
34
35
        $services = [
36
            'addJWSBuilder' => 'jose.jws_builder',
37
            'addJWSVerifier' => 'jose.jws_verifier',
38
            'addJWSLoader' => 'jose.jws_loader',
39
        ];
40
        foreach ($services as $method => $tag) {
41
            $this->collectServices($method, $tag, $definition, $container);
42
        }
43
    }
44
45
    private function collectServices(string $method, string $tag, Definition $definition, ContainerBuilder $container): void
46
    {
47
        $taggedJWSServices = $container->findTaggedServiceIds($tag);
48
        foreach ($taggedJWSServices as $id => $tags) {
49
            $definition->addMethodCall($method, [$id, new Reference($id)]);
50
        }
51
    }
52
}
53