RegisterHttpHeaderFactoriesPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 21
loc 21
ccs 12
cts 12
cp 1
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
crap 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\DependencyInjection\Compiler;
5
6
use Innmind\Rest\ServerBundle\Exception\MissingAlias;
7
use Symfony\Component\DependencyInjection\{
8
    ContainerBuilder,
9
    Compiler\CompilerPassInterface,
10
    Reference
11
};
12
13 View Code Duplication
final class RegisterHttpHeaderFactoriesPass implements CompilerPassInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 48
    public function process(ContainerBuilder $container)
19
    {
20 48
        $ids = $container->findTaggedServiceIds(
21 48
            'innmind_rest_server.http_header_factory'
22
        );
23 48
        $factories = [];
24
25 48
        foreach ($ids as $id => $tags) {
26 48
            foreach ($tags as $tag => $attributes) {
27 48
                if (!isset($attributes['alias'])) {
28 2
                    throw new MissingAlias;
29
                }
30
31 48
                $factories[$attributes['alias']] = new Reference($id);
32
            }
33
        }
34
35
        $container
36 46
            ->getDefinition('innmind_rest_server.http.factory.header.default')
37 46
            ->addArgument($factories);
38 46
    }
39
}
40