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

SlugNormalizerPass::process()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 7.004

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 22
cts 23
cp 0.9565
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 18
nc 13
nop 1
crap 7.004
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 SlugNormalizerPass implements CompilerPassInterface
10
{
11
    /** {@inheritdoc} */
12 1
    public function process(ContainerBuilder $container)
13
    {
14 1
        if (!$container->has('bankiru.seo.slug.delegated_normalizer')) {
15
            return;
16
        }
17
18 1
        $normalizer = $container->getDefinition('bankiru.seo.slug.delegated_normalizer');
19 1
        $services   = $container->findTaggedServiceIds('seo_slug_normalizer');
20
21
        /** @var Reference[][] $normalizers */
22 1
        $normalizers = [];
23 1
        foreach ($services as $id => $tags) {
24 1
            foreach ($tags as $attributes) {
25 1
                $priority                 = array_key_exists('priority', $attributes) ?
26 1
                    (int)$attributes['priority'] :
27 1
                    0;
28 1
                $normalizers[$priority][] = new Reference($id);
29 1
            }
30 1
        }
31
32 1
        ksort($normalizers);
33
34 1
        $flat = [];
35 1
        foreach ($normalizers as $priority => $pNormalizers) {
36 1
            foreach ($pNormalizers as $pNormalizer) {
37 1
                $flat[] = $pNormalizer;
38 1
            }
39 1
        }
40
41 1
        $normalizer->replaceArgument(0, $flat);
42 1
    }
43
}
44