SeoGeneratorPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 22 6
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
/**
9
 * Description of SeoGeneratorPass.
10
 *
11
 * @author: leogout
12
 */
13
class SeoGeneratorPass implements CompilerPassInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function process(ContainerBuilder $container)
19
    {
20
        $definition = $container->getDefinition('leogout_seo.provider.generator');
21
        $taggedServices = $container->findTaggedServiceIds('leogout_seo.generator');
22
        $seoGenerators = [];
23
        foreach ($taggedServices as $id => $tags) {
24
            $generatorDefinition = $container->getDefinition($id);
25
            if (!$generatorDefinition->isPublic()) {
26
                throw new \InvalidArgumentException(sprintf('Seo generator services must be public, but "%s" is not.', $id));
27
            }
28
            if ($generatorDefinition->isAbstract()) {
29
                throw new \InvalidArgumentException(sprintf('Seo generator services cannot be abstract but "%s" is.', $id));
30
            }
31
            foreach ($tags as $attributes) {
32
                if (empty($attributes['alias'])) {
33
                    throw new \InvalidArgumentException(sprintf('Tag "leogout_seo.generator" requires an "alias" field in "%s" definition.', $id));
34
                }
35
                $seoGenerators[$attributes['alias']] = $container->findDefinition($id);
36
            }
37
        }
38
        $definition->replaceArgument(0, $seoGenerators);
39
    }
40
}
41