Passed
Push — master ( 146be5...1e12ef )
by ANTHONIUS
06:12
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
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Bridge\CodeCoverage\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
class ReportPass implements CompilerPassInterface
22
{
23 21
    public function process(ContainerBuilder $container)
24
    {
25 21
        $reports = $container->getParameter('reports');
26 21
        foreach ($reports as $type => $config) {
27 21
            $this->processConfig($container, $type, $config);
28
        }
29
30 21
        $coverage = $container->getDefinition('coverage');
31 21
        $coverage->addMethodCall('addSubscriber', [new Reference('report')]);
32
    }
33
34 21
    private function processConfig(ContainerBuilder $container, $type, $config)
35
    {
36 21
        if (!isset($config['target'])) {
37 15
            return;
38
        }
39
40 7
        if ('text' !== $type) {
41 7
            $config['target'] = getcwd().\DIRECTORY_SEPARATOR.$config['target'];
42
        }
43 7
        $report = $container->getDefinition('report');
44
45 7
        $id    = 'reports.'.$type;
46 7
        $class = $container->getParameter($id.'.class');
47
48 7
        $definition = new Definition($class);
49 7
        $definition->addArgument($config);
50 7
        $definition->setPublic(true);
51
52 7
        $container->setDefinition($id, $definition);
53
54 7
        $report->addMethodCall('addProcessor', [new Reference($id)]);
55
    }
56
}
57