Code Duplication    Length = 28-30 lines in 2 locations

src/Kunstmaan/AdminBundle/DependencyInjection/Compiler/AddLogProcessorsCompilerPass.php 1 location

@@ 12-39 (lines=28) @@
9
/**
10
 * This compiler pass makes it possible to add processors for the Kunstmaan logger
11
 */
12
class AddLogProcessorsCompilerPass implements CompilerPassInterface
13
{
14
    public function process(ContainerBuilder $container)
15
    {
16
        if (!$container->hasDefinition('kunstmaan_admin.logger')) {
17
            return;
18
        }
19
20
        $definition = $container->getDefinition('kunstmaan_admin.logger');
21
22
        foreach ($container->findTaggedServiceIds('kunstmaan_admin.logger.processor') as $id => $tags) {
23
            foreach ($tags as $tag) {
24
                if (!empty($tag['method'])) {
25
                    $processor = [new Reference($id), $tag['method']];
26
                } else {
27
                    // If no method is defined, fallback to use __invoke
28
                    $processor = new Reference($id);
29
                }
30
                $definition->addMethodCall('pushProcessor', [$processor]);
31
            }
32
        }
33
    }
34
}
35

src/Kunstmaan/DashboardBundle/DependencyInjection/Compiler/WidgetCompilerPass.php 1 location

@@ 9-38 (lines=30) @@
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class WidgetCompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * You can modify the container here before it is dumped to PHP code.
13
     *
14
     * @api
15
     */
16
    public function process(ContainerBuilder $container)
17
    {
18
        if (!$container->hasDefinition('kunstmaan_dashboard.manager.widgets')) {
19
            return;
20
        }
21
22
        $definition = $container->getDefinition('kunstmaan_dashboard.manager.widgets');
23
24
        foreach ($container->findTaggedServiceIds('kunstmaan_dashboard.widget') as $id => $tags) {
25
            foreach ($tags as $tag) {
26
                if (!empty($tag['method'])) {
27
                    $widget = [new Reference($id), $tag['method']];
28
                } else {
29
                    $widget = new Reference($id);
30
                }
31
                $definition->addMethodCall('addWidget', [$widget]);
32
            }
33
        }
34
    }
35
}
36