Completed
Push — master ( 6b1baa...9e395d )
by ANTHONIUS
16s queued 11s
created

ReportPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Doyo\Bridge\CodeCoverage\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class ReportPass implements CompilerPassInterface
11
{
12 15
    public function process(ContainerBuilder $container)
13
    {
14 15
        $reports = $container->getParameter('reports');
15 15
        foreach($reports as $type => $config){
16 15
            $this->processConfig($container, $type, $config);
17
        }
18
19 15
        $coverage = $container->getDefinition('coverage');
20 15
        $coverage->addMethodCall('addSubscriber', [new Reference('report')]);
21
    }
22
23 15
    private function processConfig(ContainerBuilder $container, $type, $config)
24
    {
25 15
        if(!isset($config['target'])){
26 9
            return;
27
        }
28
29 7
        if($type !== 'text'){
30 7
            $config['target'] = getcwd().DIRECTORY_SEPARATOR.$config['target'];
31
        }
32 7
        $report = $container->getDefinition('report');
33
34 7
        $id = 'reports.'.$type;
35 7
        $class = $container->getParameter($id.'.class');
36
37 7
        $definition = new Definition($class);
38 7
        $definition->addArgument($config);
39 7
        $definition->setPublic(true);
40
41 7
        $container->setDefinition($id, $definition);
42
43 7
        $report->addMethodCall('addProcessor', [new Reference($id)]);
44
    }
45
46
}
47