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
    /**
15
     * @param ContainerBuilder $container
16
     */
17
    public function process(ContainerBuilder $container)
18
    {
19
        if (!$container->hasDefinition('kunstmaan_admin.logger')) {
20
            return;
21
        }
22
23
        $definition = $container->getDefinition('kunstmaan_admin.logger');
24
25
        foreach ($container->findTaggedServiceIds('kunstmaan_admin.logger.processor') as $id => $tags) {
26
            foreach ($tags as $tag) {
27
                if (!empty($tag['method'])) {
28
                    $processor = array(new Reference($id), $tag['method']);
29
                } else {
30
                    // If no method is defined, fallback to use __invoke
31
                    $processor = new Reference($id);
32
                }
33
                $definition->addMethodCall('pushProcessor', array($processor));
34
            }
35
        }
36
    }
37
}
38

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
     * @param ContainerBuilder $container
15
     *
16
     * @api
17
     */
18
    public function process(ContainerBuilder $container)
19
    {
20
        if (!$container->hasDefinition('kunstmaan_dashboard.manager.widgets')) {
21
            return;
22
        }
23
24
        $definition = $container->getDefinition('kunstmaan_dashboard.manager.widgets');
25
26
        foreach ($container->findTaggedServiceIds('kunstmaan_dashboard.widget') as $id => $tags) {
27
            foreach ($tags as $tag) {
28
                if (!empty($tag['method'])) {
29
                    $widget = array(new Reference($id), $tag['method']);
30
                } else {
31
                    $widget = new Reference($id);
32
                }
33
                $definition->addMethodCall('addWidget', array($widget));
34
            }
35
        }
36
    }
37
}
38