Completed
Push — master ( 985011...27fff5 )
by Tobias
17:41 queued 07:46
created

app/AppKernel.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Symfony\Component\HttpKernel\Kernel;
4
use Symfony\Component\Config\Loader\LoaderInterface;
5
6
class AppKernel extends Kernel
7
{
8
    private $projectDir;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
9
10
    public function registerBundles()
11
    {
12
        $bundles = [
13
            new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
14
            new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
15
            new \Symfony\Bundle\TwigBundle\TwigBundle(),
16
            new \Symfony\Bundle\WebServerBundle\WebServerBundle(),
17
            new \Translation\Bundle\TranslationBundle(),
18
            new \AppBundle\AppBundle(),
19
20
            new \Translation\PlatformAdapter\Loco\Bridge\Symfony\TranslationAdapterLocoBundle(),
21
            new \Translation\PlatformAdapter\Phraseapp\Bridge\Symfony\TranslationAdapterPhraseAppBundle(),
22
        ];
23
24
        return $bundles;
0 ignored issues
show
The expression return $bundles; seems to be an array, but some of its elements' types (Translation\PlatformAdap...nAdapterPhraseAppBundle) 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...
25
    }
26
27
    public function getRootDir()
28
    {
29
        return __DIR__;
30
    }
31
32
    public function getCacheDir()
33
    {
34
        return sys_get_temp_dir().'/php-translation/var/cache/'.$this->getEnvironment();
35
    }
36
37
    public function getLogDir()
38
    {
39
        return sys_get_temp_dir().'/php-translation/var/logs';
40
    }
41
42
    public function registerContainerConfiguration(LoaderInterface $loader)
43
    {
44
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
45
        $config = getcwd().'/translation.yml';
46
        if (file_exists($config)) {
47
            $loader->load($config);
48
        }
49
    }
50
51
    /**
52
     * Gets the application root dir (path of the project's LICENSE file).
53
     *
54
     * @return string The project root dir
55
     */
56
    public function getProjectDir()
57
    {
58
        if (null === $this->projectDir) {
59
            $r = new \ReflectionObject($this);
60
            $dir = $rootDir = dirname($r->getFileName());
0 ignored issues
show
$rootDir is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
            while (!file_exists($dir.'/LICENSE')) {
62
                if ($dir === dirname($dir)) {
63
                    return $this->projectDir = parent::getProjectDir();
64
                }
65
                $dir = dirname($dir);
66
            }
67
            $this->projectDir = $dir;
68
        }
69
70
        return $this->projectDir;
71
    }
72
}
73