Completed
Push — master ( 66ec7e...c9ec0a )
by Matze
07:32
created

ConfigCompilerPass::process()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0092

Importance

Changes 15
Bugs 0 Features 4
Metric Value
c 15
b 0
f 4
dl 0
loc 18
ccs 11
cts 12
cp 0.9167
rs 9.2
cc 4
eloc 11
nc 6
nop 1
crap 4.0092
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 3
    public function process(ContainerBuilder $container)
23
    {
24 3
        $loader     = new XmlFileLoader($container, new FileLocator('config'));
25 3
        $filesystem = new Filesystem();
26
27 3
        if ($filesystem->exists(ROOT . 'app/container.xml')) {
28
            $loader->load(ROOT . 'app/container.xml');
29 3
        } elseif ($filesystem->exists(ROOT . '/container.xml')) {
30 3
            $loader->load(ROOT . '/container.xml');
31
        }
32
33 3
        $container->setParameter('dicId', uniqid());
34
35 3
        if (!$container->hasParameter('debug')) { // todo more into expression language in container.xml ?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
36 3
            $environment = $container->getParameter('environment');
37 3
            $container->setParameter('debug', $environment !== Environment::PRODUCTION);
38
        }
39 3
    }
40
}
41