Completed
Push — master ( dc6a94...5d02ae )
by Rafał
09:03
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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBundles() 0 9 4
A configureContainer() 3 19 3
A configureRoutes() 3 12 3
A getCacheDir() 0 4 1
A getLogDir() 0 4 1

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
use Symfony\Component\Config\Loader\LoaderInterface;
6
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
7
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
class Kernel extends BaseKernel
11
{
12
    use MicroKernelTrait;
13
14
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
15
16
    public function registerBundles()
17
    {
18
        $contents = require $this->getProjectDir().'/config/bundles.php';
19
        foreach ((array) $contents as $class => $envs) {
20
            if (isset($envs['all']) || isset($envs[$this->environment])) {
21
                yield new $class();
22
            }
23
        }
24
    }
25
26
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
27
    {
28
        $container->setParameter('container.autowiring.strict_mode', true);
29
        $container->setParameter('container.dumper.inline_class_loader', true);
30
        $confDir = $this->getProjectDir().'/config';
31
32
        // old configuration
33
        $loader->load($this->getProjectDir().'/app/config/config.yml');
34
        if (\file_exists($this->getProjectDir().'/app/config/config_'.$this->getEnvironment().'.yml')) {
35
            $loader->load($this->getProjectDir().'/app/config/config_'.$this->getEnvironment().'.yml');
36
        }
37
38
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
39 View Code Duplication
        if (is_dir($confDir.'/packages/'.$this->environment)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
41
        }
42
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
43
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
44
    }
45
46
    protected function configureRoutes(\Symfony\Component\Routing\RouteCollectionBuilder $routes)
47
    {
48
        $confDir = $this->getProjectDir().'/config';
49
        if (is_dir($confDir.'/routes/')) {
50
            $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
51
        }
52 View Code Duplication
        if (is_dir($confDir.'/routes/'.$this->environment)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
            $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
54
        }
55
56
        $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
57
    }
58
59
    public function getCacheDir(): string
60
    {
61
        return $this->getProjectDir().'/var/cache/'.$this->environment;
62
    }
63
64
    public function getLogDir(): string
65
    {
66
        return $this->getProjectDir().'/var/log';
67
    }
68
}
69