Completed
Push — master ( af42de...cc6223 )
by Florian
17s queued 11s
created

Kernel::configureRoutes()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of the feedback project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
/*
13
 * This file is part of the symfony-template project.
14
 *
15
 * (c) Florian Moser <[email protected]>
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 */
20
21
namespace App;
22
23
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
24
use Symfony\Component\Config\Loader\LoaderInterface;
25
use Symfony\Component\DependencyInjection\ContainerBuilder;
26
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
27
use Symfony\Component\Routing\RouteCollectionBuilder;
28
29
class Kernel extends BaseKernel
30
{
31
    use MicroKernelTrait;
32
33
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
34
35
    public function getCacheDir()
36
    {
37
        return $this->getProjectDir() . '/var/cache/' . $this->environment;
38
    }
39
40
    public function getLogDir()
41
    {
42
        return $this->getProjectDir() . '/var/log';
43
    }
44
45
    public function registerBundles()
46
    {
47
        $contents = require $this->getProjectDir() . '/config/bundles.php';
48
        foreach ($contents as $class => $envs) {
49
            if (isset($envs['all']) || isset($envs[$this->environment])) {
50
                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...dleInterface[]|iterable.

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...
51
            }
52
        }
53
    }
54
55
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
56
    {
57
        $container->setParameter('container.autowiring.strict_mode', true);
58
        $container->setParameter('container.dumper.inline_class_loader', true);
59
        $confDir = $this->getProjectDir() . '/config';
60
        $loader->load($confDir . '/packages/*' . self::CONFIG_EXTS, 'glob');
61
        if (is_dir($confDir . '/packages/' . $this->environment)) {
62
            $loader->load($confDir . '/packages/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
63
        }
64
        $loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob');
65
        $loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
66
    }
67
68
    protected function configureRoutes(RouteCollectionBuilder $routes)
69
    {
70
        $confDir = $this->getProjectDir() . '/config';
71
        if (is_dir($confDir . '/routes/')) {
72
            $routes->import($confDir . '/routes/*' . self::CONFIG_EXTS, '/', 'glob');
73
        }
74
        if (is_dir($confDir . '/routes/' . $this->environment)) {
75
            $routes->import($confDir . '/routes/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
76
        }
77
        $routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
78
    }
79
}
80