Completed
Pull Request — master (#40)
by Kamil
21:16
created

AppKernel   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 15

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 15
dl 0
loc 37
rs 9.1666
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBundles() 0 23 1
A registerContainerConfiguration() 0 4 1
1
<?php
2
3
use Sylius\Bundle\CoreBundle\Application\Kernel;
4
use Symfony\Component\Config\Loader\LoaderInterface;
5
6
final class AppKernel extends Kernel
7
{
8
    /**
9
     * {@inheritdoc}
10
     */
11
    public function registerBundles()
12
    {
13
        return array_merge(parent::registerBundles(), [
0 ignored issues
show
Best Practice introduced by
The expression return array_merge(paren...le\SyliusApiBundle())); seems to be an array, but some of its elements' types (Sylius\Bundle\ApiBundle\SyliusApiBundle) 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...
14
            new \Lakion\SyliusCmsBundle\LakionSyliusCmsBundle(),
15
16
            new \Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(),
17
            new \Symfony\Cmf\Bundle\CoreBundle\CmfCoreBundle(),
18
            new \Symfony\Cmf\Bundle\ContentBundle\CmfContentBundle(),
19
            new \Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
20
            new \Symfony\Cmf\Bundle\MenuBundle\CmfMenuBundle(),
21
            new \Symfony\Cmf\Bundle\MediaBundle\CmfMediaBundle(),
22
23
            new \Sonata\BlockBundle\SonataBlockBundle(),
24
            new \Sonata\CoreBundle\SonataCoreBundle(),
25
            new \Symfony\Cmf\Bundle\BlockBundle\CmfBlockBundle(),
26
27
            new \Sylius\Bundle\AdminBundle\SyliusAdminBundle(),
28
            new \Sylius\Bundle\ShopBundle\SyliusShopBundle(),
29
30
            new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), // Required by SyliusApiBundle
31
            new \Sylius\Bundle\ApiBundle\SyliusApiBundle(),
32
        ]);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function registerContainerConfiguration(LoaderInterface $loader)
39
    {
40
        $loader->load($this->getRootDir() . '/config/config.yml');
41
    }
42
}
43