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; |
||
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\Flysystem\Bridge\Symfony\TranslationAdapterFlysystemBundle(), |
||
22 | new \Translation\PlatformAdapter\PhraseApp\Bridge\Symfony\TranslationAdapterPhraseAppBundle(), |
||
23 | new \Http\HttplugBundle\HttplugBundle(), |
||
24 | ]; |
||
25 | |||
26 | return $bundles; |
||
0 ignored issues
–
show
|
|||
27 | } |
||
28 | |||
29 | public function getRootDir() |
||
30 | { |
||
31 | return __DIR__; |
||
32 | } |
||
33 | |||
34 | public function getCacheDir() |
||
35 | { |
||
36 | return sys_get_temp_dir().'/php-translation/var/cache/'.$this->getEnvironment(); |
||
37 | } |
||
38 | |||
39 | public function getLogDir() |
||
40 | { |
||
41 | return sys_get_temp_dir().'/php-translation/var/logs'; |
||
42 | } |
||
43 | |||
44 | public function registerContainerConfiguration(LoaderInterface $loader) |
||
45 | { |
||
46 | $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); |
||
47 | $config = getcwd().'/translation.yml'; |
||
48 | if (file_exists($config)) { |
||
49 | $loader->load($config); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Gets the application root dir (path of the project's LICENSE file). |
||
55 | * |
||
56 | * @return string The project root dir |
||
57 | */ |
||
58 | public function getProjectDir() |
||
59 | { |
||
60 | if (null === $this->projectDir) { |
||
61 | $r = new \ReflectionObject($this); |
||
62 | $dir = $rootDir = dirname($r->getFileName()); |
||
63 | while (!file_exists($dir.'/LICENSE')) { |
||
64 | if ($dir === dirname($dir)) { |
||
65 | return $this->projectDir = parent::getProjectDir(); |
||
66 | } |
||
67 | $dir = dirname($dir); |
||
68 | } |
||
69 | $this->projectDir = $dir; |
||
70 | } |
||
71 | |||
72 | return $this->projectDir; |
||
73 | } |
||
74 | } |
||
75 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.