RegisterResponseFactoriesPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 20
ccs 6
cts 12
cp 0.5
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 4
1
<?php
2
3
namespace Lamoda\Metric\MetricBundle\DependencyInjection\Compiler;
4
5
use Lamoda\Metric\MetricBundle\DependencyInjection\DefinitionFactory\ResponseFactory;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
final class RegisterResponseFactoriesPass implements CompilerPassInterface
10
{
11
    /** {@inheritdoc} */
12 4
    public function process(ContainerBuilder $container)
13
    {
14 4
        $services = $container->findTaggedServiceIds(ResponseFactory::TAG);
15 4
        foreach ($services as $id => $tags) {
16 4
            foreach ($tags as $attributes) {
17 4
                if (!isset($attributes[ResponseFactory::ALIAS_ATTRIBUTE])) {
18
                    throw new \InvalidArgumentException(
19
                        sprintf(
20
                            'Missing "%s" attribute for "%s" tag "%s"',
21
                            ResponseFactory::ALIAS_ATTRIBUTE,
22
                            $id,
23
                            ResponseFactory::TAG
24
                        )
25
                    );
26
                }
27
28 4
                $container->setAlias(ResponseFactory::createId($attributes[ResponseFactory::ALIAS_ATTRIBUTE]), $id);
29
            }
30
        }
31 4
    }
32
}
33