RegisterReceiversPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 22
ccs 4
cts 13
cp 0.3076
rs 10

1 Method

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