Completed
Push — master ( a3cce1...d6fbcc )
by Marcel
09:39
created

Kernel::configureContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 14
ccs 0
cts 10
cp 0
crap 2
rs 9.9666
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\Config\Resource\FileResource;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
10
use Symfony\Component\Routing\RouteCollectionBuilder;
11
12
class Kernel extends BaseKernel
13
{
14
    use MicroKernelTrait;
15
16
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
17
18 13
    public function getCacheDir()
19
    {
20 13
        return $this->getProjectDir().'/var/cache/'.$this->environment;
21
    }
22
23
    public function getLogDir()
24
    {
25
        return $this->getProjectDir().'/var/log';
26
    }
27
28 13
    public function registerBundles()
29
    {
30 13
        $contents = require $this->getProjectDir().'/config/bundles.php';
31 13
        foreach ($contents as $class => $envs) {
32 13
            if (isset($envs['all']) || isset($envs[$this->environment])) {
33 13
                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...
34
            }
35
        }
36 13
    }
37
38
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
39
    {
40
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
41
        // Feel free to remove the "container.autowiring.strict_mode" parameter
42
        // if you are using symfony/dependency-injection 4.0+ as it's the default behavior
43
        $container->setParameter('container.autowiring.strict_mode', true);
44
        $container->setParameter('container.dumper.inline_class_loader', true);
45
        $confDir = $this->getProjectDir().'/config';
46
47
        $loader->load($confDir.'/version'.self::CONFIG_EXTS, 'glob'); // load version
48
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
49
        $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
50
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
51
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
52
    }
53
54 1
    protected function configureRoutes(RouteCollectionBuilder $routes)
55
    {
56 1
        $confDir = $this->getProjectDir().'/config';
57
58 1
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
59 1
        $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
60 1
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
61
    }
62
}