Passed
Branch master (117216)
by Pavel
08:06
created

SlugNormalizerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 35
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
    public function process(ContainerBuilder $container)
13
    {
14
        if (!$container->has('bankiru.seo.slug.delegated_normalizer')) {
15
            return;
16
        }
17
18
        $normalizer = $container->getDefinition('bankiru.seo.slug.delegated_normalizer');
19
        $services   = $container->findTaggedServiceIds('seo_slug_normalizer');
20
21
        /** @var Reference[][] $normalizers */
22
        $normalizers = [];
23
        foreach ($services as $id => $tags) {
24
            foreach ($tags as $attributes) {
25
                $priority                 = array_key_exists('priority', $attributes) ?
26
                    (int)$attributes['priority'] :
27
                    0;
28
                $normalizers[$priority][] = new Reference($id);
29
            }
30
        }
31
32
        ksort($normalizers);
33
34
        $flat = [];
35
        foreach ($normalizers as $priority => $pNormalizers) {
36
            foreach ($pNormalizers as $pNormalizer) {
37
                $flat[] = $pNormalizer;
38
            }
39
        }
40
41
        $normalizer->replaceArgument(0, $flat);
42
    }
43
}
44