Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

WidgetCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 29
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 19 19 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
namespace Kunstmaan\DashboardBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9 View Code Duplication
class WidgetCompilerPass 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...
10
{
11
    /**
12
     * You can modify the container here before it is dumped to PHP code.
13
     *
14
     * @param ContainerBuilder $container
15
     *
16
     * @api
17
     */
18 2
    public function process(ContainerBuilder $container)
19
    {
20 2
        if (!$container->hasDefinition('kunstmaan_dashboard.manager.widgets')) {
21 1
            return;
22
        }
23
24 1
        $definition = $container->getDefinition('kunstmaan_dashboard.manager.widgets');
25
26 1
        foreach ($container->findTaggedServiceIds('kunstmaan_dashboard.widget') as $id => $tags) {
27 1
            foreach ($tags as $tag) {
28 1
                if (!empty($tag['method'])) {
29 1
                    $widget = array(new Reference($id), $tag['method']);
30
                } else {
31 1
                    $widget = new Reference($id);
32
                }
33 1
                $definition->addMethodCall('addWidget', array($widget));
34
            }
35
        }
36 1
    }
37
}
38