Issues (32)

src/Kernel.php (1 issue)

1
<?php
2
3
namespace App;
4
5
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
9
use Symfony\Component\Routing\RouteCollectionBuilder;
10
11
class Kernel extends BaseKernel
12
{
13
    use MicroKernelTrait;
14
15
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
16
17
    public function getCacheDir()
18
    {
19
        return $this->getProjectDir().'/var/cache/'.$this->environment;
20
    }
21
22
    public function getLogDir()
23
    {
24
        return $this->getProjectDir().'/var/log';
25
    }
26
27
    public function registerBundles()
28
    {
29
        $contents = require $this->getProjectDir().'/config/bundles.php';
30
        foreach ($contents as $class => $envs) {
31
            if (isset($envs['all']) || isset($envs[$this->environment])) {
32
                yield new $class();
0 ignored issues
show
Bug Best Practice introduced by
The expression yield new $class() returns the type Generator which is incompatible with the return type mandated by Symfony\Component\HttpKe...face::registerBundles() of Symfony\Component\HttpKe...undle\BundleInterface[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
33
            }
34
        }
35
    }
36
37
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
38
    {
39
        $container->setParameter('container.autowiring.strict_mode', true);
40
        $container->setParameter('container.dumper.inline_class_loader', true);
41
        $confDir = $this->getProjectDir().'/config';
42
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
43
        if (is_dir($confDir.'/packages/'.$this->environment)) {
44
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
45
        }
46
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
47
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
48
    }
49
50
    protected function configureRoutes(RouteCollectionBuilder $routes)
51
    {
52
        $confDir = $this->getProjectDir().'/config';
53
        if (is_dir($confDir.'/routes/')) {
54
            $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
55
        }
56
        if (is_dir($confDir.'/routes/'.$this->environment)) {
57
            $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
58
        }
59
        $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
60
    }
61
}
62