Completed
Push — master ( 61044a...94728c )
by Rafał
24:26 queued 10:49
created

Kernel   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 59
Duplicated Lines 10.17 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 6
loc 59
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A registerBundles() 0 9 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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