1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/code-coverage project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <https://itstoni.com> |
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
|
35 |
|
public function process(ContainerBuilder $container) |
24
|
|
|
{ |
25
|
35 |
|
$reports = $container->getParameter('reports'); |
26
|
35 |
|
foreach ($reports as $type => $config) { |
27
|
35 |
|
$this->processConfig($container, $type, $config); |
28
|
|
|
} |
29
|
|
|
|
30
|
35 |
|
$coverage = $container->getDefinition('coverage'); |
31
|
35 |
|
$coverage->addMethodCall('addSubscriber', [new Reference('report')]); |
32
|
|
|
} |
33
|
|
|
|
34
|
35 |
|
private function processConfig(ContainerBuilder $container, $type, $config) |
35
|
|
|
{ |
36
|
35 |
|
if (!isset($config['target'])) { |
37
|
29 |
|
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
|
|
|
|