Completed
Push — master ( e81671...a22352 )
by André
93:06 queued 73:42
created

URLHandlerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 13

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 5
nop 1
dl 23
loc 23
rs 8.5906
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
8
9
use LogicException;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Reference;
13
14
/**
15
 * This compiler pass will register URL handlers.
16
 */
17 View Code Duplication
class URLHandlerPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function process(ContainerBuilder $container)
23
    {
24
        if (!$container->hasDefinition('ezpublish.url_checker.handler_registry')) {
25
            return;
26
        }
27
28
        $definition = $container->findDefinition('ezpublish.url_checker.handler_registry');
29
        foreach ($container->findTaggedServiceIds('ezpublish.url_handler') as $id => $attributes) {
30
            foreach ($attributes as $attribute) {
31
                if (!isset($attribute['scheme'])) {
32
                    throw new LogicException(sprintf(
33
                        '%s service tag needs a "scheme" attribute to identify which scheme is supported by handler. None given.',
34
                        'ezpublish.url_handler'
35
                    ));
36
                }
37
38
                $definition->addMethodCall('addHandler', [
39
                    $attribute['scheme'],
40
                    new Reference($id),
41
                ]);
42
            }
43
        }
44
    }
45
}
46