Passed
Pull Request — master (#5)
by ANTHONIUS
03:34
created

ReportPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 36%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 34
ccs 9
cts 25
cp 0.36
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 1
    public function process(ContainerBuilder $container)
24
    {
25 1
        $reports = $container->getParameter('reports');
26 1
        foreach ($reports as $type => $config) {
27 1
            $this->processConfig($container, $type, $config);
28
        }
29
30 1
        $coverage = $container->getDefinition('coverage');
31 1
        $coverage->addMethodCall('addSubscriber', [new Reference('report')]);
32
    }
33
34 1
    private function processConfig(ContainerBuilder $container, $type, $config)
35
    {
36 1
        if (!isset($config['target'])) {
37 1
            return;
38
        }
39
40
        if ('text' !== $type) {
41
            $config['target'] = getcwd().\DIRECTORY_SEPARATOR.$config['target'];
42
        }
43
        $report = $container->getDefinition('report');
44
45
        $id    = 'reports.'.$type;
46
        $class = $container->getParameter($id.'.class');
47
48
        $definition = new Definition($class);
49
        $definition->addArgument($config);
50
        $definition->setPublic(true);
51
52
        $container->setDefinition($id, $definition);
53
54
        $report->addMethodCall('addProcessor', [new Reference($id)]);
55
    }
56
}
57