Completed
Pull Request — master (#84)
by Alessandro
02:34
created

ParallelConfiguration::buildContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

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