Passed
Pull Request — master (#1)
by ANTHONIUS
03:02
created

ReportPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 56.25%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 29
ccs 9
cts 16
cp 0.5625
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
A processConfig() 0 16 2
1
<?php
2
3
4
namespace Doyo\Bridge\CodeCoverage\Compiler;
5
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
class ReportPass implements CompilerPassInterface
13
{
14 1
    public function process(ContainerBuilder $container)
15
    {
16 1
        $reports = $container->getParameter('reports');
17 1
        foreach($reports as $type => $config){
18 1
            $this->processConfig($container, $type, $config);
19
        }
20
21 1
        $coverage = $container->getDefinition('coverage');
22 1
        $coverage->addMethodCall('addSubscriber', [new Reference('report')]);
23
    }
24
25 1
    private function processConfig(ContainerBuilder $container, $type, $config)
26
    {
27 1
        if(!isset($config['target'])){
28 1
            return;
29
        }
30
31
        $report = $container->getDefinition('report');
32
33
        $id = 'reports.'.$type;
34
        $class = $container->getParameter($id.'.class');
35
36
        $definition = new Definition($class);
37
        $definition->addArgument($config);
38
        $container->setDefinition($id, $definition);
39
40
        $report->addMethodCall('addProcessor', [new Reference($id)]);
41
    }
42
43
}
44