Completed
Push — master ( 5524a5...bc12da )
by Jeroen
54:06 queued 48:17
created

AddLogProcessorsCompilerPass::process()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 10
cts 11
cp 0.9091
rs 9.2888
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5.0187
1
<?php
2
3
namespace Kunstmaan\AdminBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * This compiler pass makes it possible to add processors for the Kunstmaan logger
11
 */
12 View Code Duplication
class AddLogProcessorsCompilerPass 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...
13
{
14
    /**
15
     * @param ContainerBuilder $container
16
     */
17 4
    public function process(ContainerBuilder $container)
18
    {
19 4
        if (!$container->hasDefinition('kunstmaan_admin.logger')) {
20
            return;
21
        }
22
23 4
        $definition = $container->getDefinition('kunstmaan_admin.logger');
24
25 4
        foreach ($container->findTaggedServiceIds('kunstmaan_admin.logger.processor') as $id => $tags) {
26 4
            foreach ($tags as $tag) {
27 4
                if (!empty($tag['method'])) {
28 4
                    $processor = array(new Reference($id), $tag['method']);
29
                } else {
30
                    // If no method is defined, fallback to use __invoke
31 1
                    $processor = new Reference($id);
32
                }
33 4
                $definition->addMethodCall('pushProcessor', array($processor));
34
            }
35
        }
36 4
    }
37
}
38