UrlMapperPass::process()   B
last analyzed

Complexity

Conditions 7
Paths 8

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 7
eloc 14
c 2
b 1
f 1
nc 8
nop 1
dl 0
loc 29
ccs 0
cts 15
cp 0
crap 56
rs 8.8333
1
<?php
2
/**
3
 * @author Rik van der Kemp <[email protected]>
4
 * @copyright Zicht Online <http://www.zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\DependencyInjection\Compiler;
8
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Zicht\Bundle\UrlBundle\Aliasing\Mapper\XmlMapper;
12
use Zicht\Bundle\UrlBundle\Url\AliasSitemapProvider;
13
14
/**
15
 * Registers all tagged services
16
 */
17
class UrlMapperPass implements CompilerPassInterface
18
{
19
    /**
20
     * @{inheritDoc}
21
     */
22
    public function process(ContainerBuilder $container)
23
    {
24
        if ($container->hasDefinition('zicht_url.aliasing') === false) {
25
            return;
26
        }
27
28
        $mappers = $container->findTaggedServiceIds('zicht_url.url_mapper');
29
30
        if (sizeof($mappers) === 0) {
31
            return;
32
        }
33
34
        $aliasing = $container->getDefinition('zicht_url.aliasing');
35
36
        $sitemapIsAliased = false;
37
38
        if ($container->getDefinition($container->getAlias('zicht_url.sitemap_provider'))->getClass() === AliasSitemapProvider::class) {
39
            // aliasing is not needed for this implementation
40
            $sitemapIsAliased = true;
41
        }
42
43
        foreach ($mappers as $serviceId => $info) {
44
            $contentMapper = $container->getDefinition($serviceId);
45
            if ($sitemapIsAliased && $contentMapper->getClass() === XmlMapper::class) {
46
                // no need for aliasing the urls in the sitemapper, because it provides it's own aliasing.
47
                // this is a performance optimization, since sitemaps can get extremely large.
48
                continue;
49
            }
50
            $aliasing->addMethodCall('addMapper', array($contentMapper));
51
        }
52
    }
53
}
54