Failed Conditions
Push — ng ( 06d981...bf1375 )
by Florent
11:23
created

AppKernel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 9
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerBundles() 0 18 1
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A registerContainerConfiguration() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Bundle\Tests;
15
16
/*
17
 * The MIT License (MIT)
18
 *
19
 * Copyright (c) 2014-2017 Spomky-Labs
20
 *
21
 * This software may be modified and distributed under the terms
22
 * of the MIT license.  See the LICENSE file for details.
23
 */
24
25
use Http\HttplugBundle\HttplugBundle;
26
use OAuth2Framework\Bundle\OAuth2FrameworkBundle;
27
use OAuth2Framework\Bundle\Tests\TestBundle\TestBundle;
28
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
29
use SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle;
30
use SimpleBus\SymfonyBridge\SimpleBusEventBusBundle;
31
use Symfony\Bundle\SecurityBundle\SecurityBundle;
32
use Symfony\Bundle\TwigBundle\TwigBundle;
33
use Symfony\Component\Config\Loader\LoaderInterface;
34
use Symfony\Component\HttpKernel\Kernel;
35
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
36
37
/**
38
 * Class AppKernel.
39
 */
40
final class AppKernel extends Kernel
41
{
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function __construct(string $environment, bool $debug)
46
    {
47
        parent::__construct($environment, false);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function registerBundles()
54
    {
55
        $bundles = [
56
            new FrameworkBundle(),
57
            new SecurityBundle(),
58
            new TwigBundle(),
59
            new SensioFrameworkExtraBundle(),
60
            new HttplugBundle(),
61
62
            new OAuth2FrameworkBundle(),
63
            new TestBundle(),
64
65
            new SimpleBusEventBusBundle(),
66
            new SimpleBusCommandBusBundle(),
67
        ];
68
69
        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 (Symfony\Bundle\SecurityB...e\TwigBundle\TwigBundle) 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...
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getCacheDir()
76
    {
77
        return sys_get_temp_dir().'/OAuth2FrameworkBundle/Test';
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getLogDir()
84
    {
85
        return sys_get_temp_dir().'/OAuth2FrameworkBundle/log';
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function registerContainerConfiguration(LoaderInterface $loader)
92
    {
93
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
94
    }
95
}
96