RegisterRequestVerifiersPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 38
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 32 6
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\DependencyInjection\Compiler;
5
6
use Innmind\Rest\ServerBundle\Exception\{
7
    MissingPriority,
8
    PriorityAlreadyUsedByAVerifier
9
};
10
use Symfony\Component\DependencyInjection\{
11
    ContainerBuilder,
12
    Compiler\CompilerPassInterface,
13
    Reference
14
};
15
16
final class RegisterRequestVerifiersPass implements CompilerPassInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 50
    public function process(ContainerBuilder $container)
22
    {
23 50
        $ids = $container->findTaggedServiceIds(
24 50
            'innmind_rest_server.http.request.verifier'
25
        );
26 50
        $definition = $container->getDefinition('innmind_rest_server.http.request.verifier');
27 50
        $verifiers = [];
28
29 50
        foreach ($ids as $id => $tags) {
30 50
            foreach ($tags as $tag => $attributes) {
31 50
                if (!isset($attributes['priority'])) {
32 2
                    throw new MissingPriority;
33
                }
34
35 50
                $priority = (int) $attributes['priority'];
36
37 50
                if (isset($verifiers[$priority])) {
38 2
                    throw new PriorityAlreadyUsedByAVerifier(
39 2
                        (string) $priority
40
                    );
41
                }
42
43 50
                $verifiers[$priority] = new Reference($id);
44
            }
45
        }
46
47 46
        krsort($verifiers);
48
49 46
        foreach ($verifiers as $verifier) {
50 46
            $definition->addArgument($verifier);
51
        }
52 46
    }
53
}
54