Completed
Pull Request — master (#66)
by Alessandro
06:05
created

ParallelConfiguration::loadCommandLineOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Paraunit\Configuration;
4
5
use Paraunit\Parser\ParserCompilerPass;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11
use Symfony\Component\DependencyInjection\Reference;
12
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
13
14
/**
15
 * Class Paraunit
16
 * @package Paraunit\Configuration
17
 */
18
class ParallelConfiguration
19
{
20
    /**
21
     * @param InputInterface $input
22
     * @return ContainerBuilder
23
     * @throws \Exception
24
     */
25 41
    public function buildContainer(InputInterface $input)
26
    {
27 41
        $containerBuilder = new ContainerBuilder();
28
29 41
        $this->loadYamlConfiguration($containerBuilder);
30 41
        $this->registerEventDispatcher($containerBuilder);
31 41
        $this->loadCommandLineOptions($containerBuilder, $input);
32 41
        $containerBuilder->compile();
33
34 41
        return $containerBuilder;
35
    }
36
37
    /**
38
     * @param ContainerBuilder $containerBuilder
39
     * @return YamlFileLoader
40
     * @throws \Exception
41
     */
42 41
    protected function loadYamlConfiguration(ContainerBuilder $containerBuilder)
43
    {
44 41
        $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../Resources/config/'));
45 41
        $loader->load('configuration.yml');
46 41
        $loader->load('file.yml');
47 41
        $loader->load('parser.yml');
48 41
        $loader->load('printer.yml');
49 41
        $loader->load('process.yml');
50 41
        $loader->load('services.yml');
51 41
        $loader->load('test_result.yml');
52 41
        $loader->load('test_result_container.yml');
53 41
        $loader->load('test_result_format.yml');
54
55 41
        $eventDispatcherPass = 'Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass';
56 41
        $deprecatedPass = 'Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass';
57 41
        if (! class_exists($eventDispatcherPass)) {
58
            class_alias($deprecatedPass, $eventDispatcherPass);
59
        }
60
61 41
        return $loader;
62
    }
63
64
    /**
65
     * @param ContainerBuilder $containerBuilder
66
     */
67 41
    private function registerEventDispatcher(ContainerBuilder $containerBuilder)
68
    {
69 41
        $containerBuilder->addCompilerPass(new RegisterListenersPass());
70 41
        $containerBuilder->addCompilerPass(new ParserCompilerPass());
71
72
        $containerBuilder->
73 41
        setDefinition(
74 41
            'event_dispatcher',
75 41
            new Definition(
76 41
                'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher',
77 41
                array(new Reference('service_container'))
78 41
            )
79 41
        );
80 41
    }
81
82 41
    protected function loadCommandLineOptions(ContainerBuilder $containerBuilder, InputInterface $input)
83
    {
84 41
    }
85
}
86