AppKernel   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerContainerConfiguration() 0 4 1
A registerBundles() 0 11 1
1
<?php
2
3
/*
4
 * This file is part of the LoopBackApiBundle package.
5
 *
6
 * (c) Théo FIDRY <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
13
use Dunglas\ApiBundle\DunglasApiBundle;
14
use Fidry\LoopBackApiBundle\LoopBackApiBundle;
15
use Fidry\LoopBackApiBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
16
use Hautelook\AliceBundle\HautelookAliceBundle;
17
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
18
use Symfony\Component\Config\Loader\LoaderInterface;
19
use Symfony\Component\HttpKernel\Kernel;
20
21
/**
22
 * Class AppKernel.
23
 *
24
 * @author Théo FIDRY <[email protected]>
25
 */
26
class AppKernel extends Kernel
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function registerBundles()
32
    {
33
        return [
0 ignored issues
show
Best Practice introduced by
The expression return array(new \Doctri...dle\FrameworkBundle()); seems to be an array, but some of its elements' types (Doctrine\Bundle\DoctrineBundle\DoctrineBundle) 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...
34
            new DoctrineBundle(),
35
            new DunglasApiBundle(),
36
            new HautelookAliceBundle(),
37
            new LoopBackApiBundle(),
38
            new TestBundle(),
39
            new FrameworkBundle(),
40
        ];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function registerContainerConfiguration(LoaderInterface $loader)
47
    {
48
        $loader->load(__DIR__.'/config/config.yml');
49
    }
50
}
51