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

URLHandlerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 29
loc 29
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 23 23 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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