Passed
Pull Request — develop (#5)
by ANTHONIUS
05:33
created

Extension::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the DoyoUserBundle 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\Behat\Coverage;
15
16
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
17
use Behat\Testwork\ServiceContainer\ExtensionManager;
18
use Doyo\Behat\Coverage\Compiler\CoveragePass;
19
use Doyo\Behat\Coverage\Compiler\DriverPass;
20
use Doyo\Behat\Coverage\Compiler\ReportPass;
21
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
22
use Symfony\Component\Config\FileLocator;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
25
use Symfony\Component\DependencyInjection\Reference;
26
27
class Extension implements ExtensionInterface
28
{
29 1
    public function process(ContainerBuilder $container)
30
    {
31 1
        $definition = $container->getDefinition('doyo.coverage.dispatcher');
32 1
        foreach ($container->findTaggedServiceIds('doyo.dispatcher.subscriber') as $id=>$arguments) {
33 1
            $service  = new Reference($id);
34 1
            $priority = $arguments[0];
35 1
            $priority = $priority['priority'] ?? null;
36 1
            $definition->addMethodCall('addSubscriber', [$service, $priority]);
37
        }
38
    }
39
40 1
    public function getConfigKey()
41
    {
42 1
        return 'doyo';
43
    }
44
45
    public function initialize(ExtensionManager $extensionManager)
46
    {
47
    }
48
49 1
    public function configure(ArrayNodeDefinition $builder)
50
    {
51 1
        $config = new Configuration();
52 1
        $config->configure($builder);
53
54 1
        return $builder;
55
    }
56
57 1
    public function load(ContainerBuilder $container, array $config)
58
    {
59 1
        $this->loadServices($container);
60
61 1
        $container->setParameter('doyo.coverage.options', $config['coverage']);
62 1
        $container->setParameter('doyo.coverage.config', $config);
63
64 1
        $reportFormats = ['clover', 'crap4j', 'html', 'php', 'text', 'xml'];
65 1
        foreach ($reportFormats as $format) {
66 1
            $name = 'doyo.coverage.report.'.$format;
67 1
            $container->setParameter($name, $config['report'][$format]);
68
        }
69
    }
70
71 1
    private function loadServices(ContainerBuilder $container)
72
    {
73 1
        $locator = new FileLocator(__DIR__.'/Resources/config');
74 1
        $loader  = new XmlFileLoader($container, $locator);
75
76 1
        $loader->load('core.xml');
77 1
        $loader->load('drivers.xml');
78 1
        $loader->load('coverage.xml');
79 1
        $loader->load('report.xml');
80
81 1
        $container->addCompilerPass(new DriverPass());
82 1
        $container->addCompilerPass(new ReportPass());
83 1
        $container->addCompilerPass(new CoveragePass());
84
    }
85
}
86