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

SlugNormalizerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 35
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 31 7
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