Kernel::configureContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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