Passed
Push — master ( 659ed2...0f05ec )
by Nicolas
05:47
created

Kernel::getProjectDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App;
6
7
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
8
use Symfony\Component\Config\Loader\LoaderInterface;
9
use Symfony\Component\Config\Resource\FileResource;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
12
use Symfony\Component\Routing\RouteCollectionBuilder;
13
14
/**
15
 * Kernel.
16
 */
17
class Kernel extends BaseKernel
18
{
19
    use MicroKernelTrait;
20
21
    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function registerBundles(): iterable
27
    {
28
        $contents = require $this->getProjectDir() . '/config/bundles.php';
29
30
        foreach ($contents as $class => $envs) {
31
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
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...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...
33
            }
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getProjectDir(): string
41
    {
42
        return \dirname(__DIR__);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
49
    {
50
        $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
51
        $container->setParameter('container.dumper.inline_class_loader', true);
52
        $confDir = $this->getProjectDir() . '/config';
53
54
        $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
55
        $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
56
        $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
57
        $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    protected function configureRoutes(RouteCollectionBuilder $routes): void
64
    {
65
        $confDir = $this->getProjectDir() . '/config';
66
67
        $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
68
        $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
69
        $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
70
    }
71
}
72