Completed
Pull Request — master (#191)
by Serhii
02:32
created

Kernel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBundles() 0 9 3
A getProjectDir() 0 4 1
A configureContainer() 0 12 2
A configureRoutes() 0 8 1
1
<?php
2
3
namespace App;
4
5
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\Config\Resource\FileResource;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
10
use Symfony\Component\Routing\RouteCollectionBuilder;
11
12
class Kernel extends BaseKernel
13
{
14
    use MicroKernelTrait;
15
16
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
17
18 48
    public function registerBundles(): iterable
19
    {
20 48
        $contents = require $this->getProjectDir().'/config/bundles.php';
21 48
        foreach ($contents as $class => $envs) {
22 48
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
23 48
                yield new $class();
24
            }
25
        }
26 48
    }
27
28 48
    public function getProjectDir(): string
29
    {
30 48
        return \dirname(__DIR__);
31
    }
32
33 1
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
34
    {
35 1
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
36 1
        $container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug);
37 1
        $container->setParameter('container.dumper.inline_factories', true);
38 1
        $confDir = $this->getProjectDir().'/config';
39
40 1
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
41 1
        $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
42 1
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
43 1
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
44 1
    }
45
46 2
    protected function configureRoutes(RouteCollectionBuilder $routes): void
47
    {
48 2
        $confDir = $this->getProjectDir().'/config';
49
50 2
        $routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
51 2
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
52 2
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
53 2
    }
54
}
55