Completed
Push — refonte ( 64e01a...7173e3 )
by Arnaud
03:31
created

AppKernel2::getLogDir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
use Symfony\Component\Config\Loader\LoaderInterface;
4
use Symfony\Component\HttpKernel\Kernel;
5
6
class AppKernel2 extends Kernel
7
{
8
    public function registerBundles()
9
    {
10
        return [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(new \Symfon...ndle\TestTestBundle()); (array<Symfony\Bundle\Fra...tBundle\TestTestBundle>) is 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 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('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...
11
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
12
            new Symfony\Bundle\TwigBundle\TwigBundle(),
13
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
14
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
15
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
16
            new Symfony\Bundle\MonologBundle\MonologBundle(),
17
            new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(),
18
            new LAG\AdminBundle\LAGAdminBundle(),
19
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
20
            new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
21
            new Test\TestBundle\TestTestBundle(),
22
        ];
23
    }
24
25
    public function registerContainerConfiguration(LoaderInterface $loader)
26
    {
27
        $loader->load(__DIR__.'/config/config_test.yml');
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getCacheDir()
34
    {
35
        $cacheDir = sys_get_temp_dir().'/phpunit/cache';
36
37
        if (!is_dir($cacheDir)) {
38
            mkdir($cacheDir, 0777, true);
39
        }
40
41
        return $cacheDir;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getLogDir()
48
    {
49
        $logDir = sys_get_temp_dir().'/phpunit/logs';
50
51
        if (!is_dir($logDir)) {
52
            mkdir($logDir, 0777, true);
53
        }
54
55
        return $logDir;
56
    }
57
}
58