Completed
Push — master ( 74d784...d308b8 )
by Alessandro
06:27
created

ParallelConfiguration::loadYamlConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2.0065

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 15
cts 17
cp 0.8824
rs 9.3142
cc 2
eloc 16
nc 2
nop 1
crap 2.0065
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 42
    public function buildContainer(InputInterface $input)
25
    {
26 42
        $containerBuilder = new ContainerBuilder();
27
28 42
        $this->loadYamlConfiguration($containerBuilder);
29 42
        $this->registerEventDispatcher($containerBuilder);
30 42
        $this->loadCommandLineOptions($containerBuilder, $input);
31 42
        $containerBuilder->compile();
32
33 42
        return $containerBuilder;
34
    }
35
36
    /**
37
     * @param ContainerBuilder $containerBuilder
38
     * @return YamlFileLoader
39
     * @throws \Exception
40
     */
41 42
    protected function loadYamlConfiguration(ContainerBuilder $containerBuilder)
42
    {
43 42
        $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../Resources/config/'));
44 42
        $loader->load('configuration.yml');
45 42
        $loader->load('file.yml');
46 42
        $loader->load('parser.yml');
47 42
        $loader->load('printer.yml');
48 42
        $loader->load('process.yml');
49 42
        $loader->load('services.yml');
50 42
        $loader->load('test_result.yml');
51 42
        $loader->load('test_result_container.yml');
52 42
        $loader->load('test_result_format.yml');
53
54 42
        $eventDispatcherPass = 'Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass';
55 42
        $deprecatedPass = 'Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass';
56 42
        if (! class_exists($eventDispatcherPass)) {
57
            class_alias($deprecatedPass, $eventDispatcherPass);
58
        }
59
60 42
        return $loader;
61
    }
62
63
    /**
64
     * @param ContainerBuilder $containerBuilder
65
     * @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
66
     */
67 42
    private function registerEventDispatcher(ContainerBuilder $containerBuilder)
68
    {
69 42
        $containerBuilder->addCompilerPass(new RegisterListenersPass());
70
71 42
        $containerBuilder->setDefinition(
72 42
            'event_dispatcher',
73 42
            new Definition(
74 42
                'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher',
75 42
                array(new Reference('service_container'))
76 42
            )
77 42
        );
78 42
    }
79
80 42
    protected function loadCommandLineOptions(ContainerBuilder $containerBuilder, InputInterface $input)
81
    {
82 42
        $containerBuilder->setParameter('paraunit.max_process_count', $input->getOption('parallel'));
83 42
    }
84
}
85