Completed
Push — master ( c4b22f...ba9072 )
by Matze
08:46
created

ConfigCompilerPass::process()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.3244

Importance

Changes 14
Bugs 0 Features 4
Metric Value
c 14
b 0
f 4
dl 0
loc 16
ccs 8
cts 11
cp 0.7272
rs 9.2
cc 4
eloc 10
nc 6
nop 1
crap 4.3244
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use BrainExe\Core\Environment;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
11
use Symfony\Component\Filesystem\Filesystem;
12
13
/**
14
 * @CompilerPass(priority=10)
15
 */
16
class ConfigCompilerPass implements CompilerPassInterface
17
{
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 2
    public function process(ContainerBuilder $container)
23
    {
24 2
        $loader     = new XmlFileLoader($container, new FileLocator('config'));
25 2
        $filesystem = new FileSystem();
26
27 2
        if ($filesystem->exists(ROOT . 'app/container.xml')) {
28
            $loader->load(ROOT . 'app/container.xml');
29 2
        } elseif ($filesystem->exists(ROOT . '/container.xml')) {
30 2
            $loader->load(ROOT . '/container.xml');
31
        }
32
33 2
        if (!$container->hasParameter('debug')) {
34
            $environment = $container->getParameter('environment');
35
            $container->setParameter('debug', $environment !== Environment::PRODUCTION);
36
        }
37 2
    }
38
}
39