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

WidgetCompilerPass::process()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 11
cts 11
cp 1
rs 9.3222
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5
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