Completed
Push — master ( b77c5c...4fbeac )
by Jeroen
10s
created

TaskCompilerPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 37
loc 37
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 34 34 6

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
 * This file is part of the Conveyor package.
5
 *
6
 * (c) Jeroen Fiege <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webcreate\Conveyor\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * Pass to add tagged tasks to the TaskFactory
19
 *
20
 */
21 View Code Duplication
class TaskCompilerPass 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...
22
{
23 3
    public function process(ContainerBuilder $container)
24
    {
25 3
        if (!$container->hasDefinition('task.factory')) {
26
            return;
27
        }
28
29 3
        $definition = $container->getDefinition('task.factory');
30 3
        $taggedServices = $container->findTaggedServiceIds('task');
31
32 3
        foreach ($taggedServices as $id => $tagsAttributes) {
33 3
            foreach ($tagsAttributes as $attributes) {
34 3
                $taskDefinition = $container->getDefinition($id);
35 3
                $taskDefinition->setScope('prototype');
36
37
                $attributes += array(
38 3
                    'alias'         => $id,
39
                    'configuration' => false,
40
                );
41
42
                // validate configuration attribute
43 3
                if (false !== $attributes['configuration']) {
44 3
                    $ref = new \ReflectionClass($attributes['configuration']);
45 3
                    if (!$ref->implementsInterface('Symfony\Component\Config\Definition\ConfigurationInterface')) {
46
                        throw new \Exception(sprintf('The tag attribute "configuration" for service "%s" must implement "Symfony\Component\Config\Definition\ConfigurationInterface"', $id));
47
                    }
48
                }
49
50 3
                $definition->addMethodCall(
51 3
                    'addTask',
52 3
                    array($id, $attributes['alias'], $attributes['configuration'])
53
                );
54
            }
55
        }
56 3
    }
57
}
58