RegisterHttpHeaderFactoriesPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 27
loc 27
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 21 21 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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