Passed
Pull Request — master (#35)
by Jacques
12:45 queued 38s
created

Kernel::getProjectDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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