Kernel   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 7
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainerBaseClass() 0 8 2
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A registerBundles() 0 9 4
A build() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App;
13
14
use App\DependencyInjection\Compiler\ServicesPass;
15
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
16
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
17
use Symfony\Component\Config\Loader\LoaderInterface;
18
use Symfony\Component\Config\Resource\FileResource;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
21
use Symfony\Component\Routing\RouteCollectionBuilder;
22
23
class Kernel extends BaseKernel
24
{
25
    use MicroKernelTrait;
26
27
    public const VERSION = '0.1.0-dev';
28
29
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function getContainerBaseClass()
35
    {
36
        if (in_array($this->getEnvironment(), ['test', 'test_cached'], true)) {
37
            return MockerContainer::class;
38
        }
39
40
        return parent::getContainerBaseClass();
41
    }
42
43
    public function getCacheDir()
44
    {
45
        return $this->getProjectDir().'/var/cache/'.$this->environment;
46
    }
47
48
    public function getLogDir()
49
    {
50
        return $this->getProjectDir().'/var/log';
51
    }
52
53
    public function registerBundles(): iterable
54
    {
55
        $contents = require $this->getProjectDir().'/config/bundles.php';
56
        foreach ($contents as $class => $envs) {
57
            if (isset($envs['all']) || isset($envs[$this->environment])) {
58
                yield new $class();
59
            }
60
        }
61
    }
62
63
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
64
    {
65
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
66
        $container->setParameter('container.dumper.inline_class_loader', true);
67
        $confDir = $this->getProjectDir().'/config';
68
69
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
70
        $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
71
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
72
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
73
    }
74
75
    protected function configureRoutes(RouteCollectionBuilder $routes): void
76
    {
77
        $confDir = $this->getProjectDir().'/config';
78
79
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
80
        $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
81
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
82
    }
83
84
    protected function build(ContainerBuilder $container): void
85
    {
86
        $container->addCompilerPass(new ServicesPass());
87
    }
88
}
89