Completed
Push — master ( b489fc...382b22 )
by Pavel
02:38
created

SeoSourcePass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 24
ccs 7
cts 14
cp 0.5
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 20 5
1
<?php
2
3
namespace Bankiru\Seo\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
final class SeoSourcePass implements CompilerPassInterface
10
{
11
    /** {@inheritdoc} */
12 1
    public function process(ContainerBuilder $container)
13
    {
14 1
        if (!$container->has('bankiru.seo.source_registry')) {
15
            return;
16
        }
17
18 1
        $registry = $container->getDefinition('bankiru.seo.source_registry');
19 1
        $services = $container->findTaggedServiceIds('seo_source');
20
21 1
        foreach ($services as $id => $tags) {
22
            foreach ($tags as $attributes) {
23
                if (!array_key_exists('code', $attributes)) {
24
                    throw new \RuntimeException(sprintf('No code configured for %s' . $id));
25
                }
26
                $code = $attributes['code'];
27
28
                $registry->addMethodCall('add', [$code, new Reference($id)]);
29
            }
30 1
        }
31 1
    }
32
}
33