Passed
Push — master ( 146be5...1e12ef )
by ANTHONIUS
06:12
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
/*
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