Completed
Push — master ( 674d5a...194be7 )
by Gorka
04:12
created

AppKernel   C

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 9.62 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 0
Metric Value
dl 5
loc 52
rs 6.875
c 0
b 0
f 0
wmc 6
lcom 1
cbo 19

5 Methods

Rating   Name   Duplication   Size   Complexity  
B registerBundles() 5 29 2
A getRootDir() 0 4 1
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A registerContainerConfiguration() 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
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
/*
16
 * This file is part of the Kreta package.
17
 *
18
 * (c) Beñat Espiña <[email protected]>
19
 * (c) Gorka Laucirica <[email protected]>
20
 *
21
 * For the full copyright and license information, please view the LICENSE
22
 * file that was distributed with this source code.
23
 */
24
25
namespace Kreta\TaskManager\Infrastructure\Symfony\Framework;
26
27
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
28
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
29
use Http\HttplugBundle\HttplugBundle;
30
use Kreta\TaskManager\Infrastructure\Symfony\Bundle\AppBundle;
31
use Nelmio\CorsBundle\NelmioCorsBundle;
32
use OldSound\RabbitMqBundle\OldSoundRabbitMqBundle;
33
use Overblog\GraphQLBundle\OverblogGraphQLBundle;
34
use Sensio\Bundle\DistributionBundle\SensioDistributionBundle;
35
use SimpleBus\SymfonyBridge\DoctrineOrmBridgeBundle;
36
use SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle;
37
use SimpleBus\SymfonyBridge\SimpleBusEventBusBundle;
38
use Symfony\Bundle\DebugBundle\DebugBundle;
39
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
40
use Symfony\Bundle\MonologBundle\MonologBundle;
41
use Symfony\Bundle\SecurityBundle\SecurityBundle;
42
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
43
use Symfony\Bundle\TwigBundle\TwigBundle;
44
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
45
use Symfony\Component\Config\Loader\LoaderInterface;
46
use Symfony\Component\HttpKernel\Kernel;
47
use Warezgibzzz\QueryBusBundle\WarezgibzzzQueryBusBundle;
48
49
class AppKernel extends Kernel
50
{
51
    public function registerBundles()
52
    {
53
        $bundles = [
54
            new AppBundle(),
55
            new DoctrineBundle(),
56
            new DoctrineMigrationsBundle(),
57
            new DoctrineOrmBridgeBundle(),
58
            new FrameworkBundle(),
59
            new HttplugBundle(),
60
            new MonologBundle(),
61
            new NelmioCorsBundle(),
62
            new OldSoundRabbitMqBundle(),
63
            new OverblogGraphQLBundle(),
64
            new SecurityBundle(),
65
            new SimpleBusCommandBusBundle(),
66
            new SimpleBusEventBusBundle(),
67
            new SwiftmailerBundle(),
68
            new TwigBundle(),
69
            new WarezgibzzzQueryBusBundle(),
70
        ];
71
72 View Code Duplication
        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
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...
73
            $bundles[] = new DebugBundle();
74
            $bundles[] = new SensioDistributionBundle();
75
            $bundles[] = new WebProfilerBundle();
76
        }
77
78
        return $bundles;
0 ignored issues
show
Best Practice introduced by
The expression return $bundles; seems to be an array, but some of its elements' types (Http\HttplugBundle\Httpl...e\OverblogGraphQLBundle) are incompatible with the return type declared by the interface Symfony\Component\HttpKe...erface::registerBundles of type Symfony\Component\HttpKe...undle\BundleInterface[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
79
    }
80
81
    public function getRootDir()
82
    {
83
        return __DIR__;
84
    }
85
86
    public function getCacheDir()
87
    {
88
        return dirname(__DIR__) . '/../../../../../var/cache/' . $this->getEnvironment();
89
    }
90
91
    public function getLogDir()
92
    {
93
        return dirname(__DIR__) . '/../../../../../var/logs';
94
    }
95
96
    public function registerContainerConfiguration(LoaderInterface $loader)
97
    {
98
        $loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml');
99
    }
100
}
101