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

ReportPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 34
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
A processConfig() 0 21 3
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