Completed
Push — master ( 400051...4d5855 )
by Alessandro
07:06
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.0009

Importance

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