Kernel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

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

2 Methods

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