UrlMapperPass   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 15
c 2
b 1
f 1
dl 0
loc 34
ccs 0
cts 15
cp 0
rs 10
wmc 7

1 Method

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