Kernel   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 8 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A registerBundles() 0 10 4

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
namespace App;
4
5
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
9
use Symfony\Component\Routing\RouteCollectionBuilder;
10
11
/**
12
 * Class Kernel
13
 *
14
 * @package App
15
 */
16
class Kernel extends BaseKernel
17
{
18
    use MicroKernelTrait;
19
20
    /**
21
     * @const string
22
     */
23
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getCacheDir()
29
    {
30
        return $this->getProjectDir().'/var/cache/'.$this->environment;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getLogDir()
37
    {
38
        return $this->getProjectDir().'/var/log';
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function registerBundles()
45
    {
46
        $contents = require $this->getProjectDir().'/config/bundles.php';
47
48
        foreach ($contents as $class => $envs) {
49
            if (isset($envs['all']) || isset($envs[$this->environment])) {
50
                yield new $class();
51
            }
52
        }
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
59
    {
60
        $container->setParameter('container.autowiring.strict_mode', true);
61
        $container->setParameter('container.dumper.inline_class_loader', true);
62
        $confDir = $this->getProjectDir().'/config';
63
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
64
65 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...
66
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
67
        }
68
69
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
70
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function configureRoutes(RouteCollectionBuilder $routes)
77
    {
78
        $confDir = $this->getProjectDir().'/config';
79
80
        if (is_dir($confDir.'/routes/')) {
81
            $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
82
        }
83
84 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...
85
            $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
86
        }
87
88
        $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
89
    }
90
}
91