These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
10 | { |
||
11 | /** |
||
12 | * You can modify the container here before it is dumped to PHP code. |
||
13 | * |
||
14 | * @api |
||
15 | */ |
||
16 | 2 | public function process(ContainerBuilder $container) |
|
17 | { |
||
18 | 2 | if (!$container->hasDefinition('kunstmaan_dashboard.manager.widgets')) { |
|
19 | 1 | return; |
|
20 | } |
||
21 | |||
22 | 1 | $definition = $container->getDefinition('kunstmaan_dashboard.manager.widgets'); |
|
23 | |||
24 | 1 | foreach ($container->findTaggedServiceIds('kunstmaan_dashboard.widget') as $id => $tags) { |
|
25 | 1 | foreach ($tags as $tag) { |
|
26 | 1 | if (!empty($tag['method'])) { |
|
27 | 1 | $widget = [new Reference($id), $tag['method']]; |
|
28 | } else { |
||
29 | 1 | $widget = new Reference($id); |
|
30 | } |
||
31 | 1 | $definition->addMethodCall('addWidget', [$widget]); |
|
32 | } |
||
33 | } |
||
34 | 1 | } |
|
35 | } |
||
36 |
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.