ValidatorCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

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

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 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\DependencyInjection\Compiler;
12
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
/**
18
 * ValidatorCompilerPass
19
 *
20
 * @author jobou
21
 */
22 View Code Duplication
class ValidatorCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function process(ContainerBuilder $container)
28
    {
29
        if (!$container->hasDefinition('jb_fileuploader.validator_chain')) {
30
            return;
31
        }
32
33
        $definition = $container->getDefinition(
34
            'jb_fileuploader.validator_chain'
35
        );
36
37
        $taggedServices = $container->findTaggedServiceIds(
38
            'jb_fileuploader.validator'
39
        );
40
41
        foreach ($taggedServices as $id => $tags) {
42
            foreach ($tags as $attributes) {
43
                $definition->addMethodCall(
44
                    'addValidator',
45
                    array(new Reference($id), $attributes["alias"])
46
                );
47
            }
48
        }
49
    }
50
}
51