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

SeoSourcePass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 8.125

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 7
cts 14
cp 0.5
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 5
nop 1
crap 8.125
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