Kernel   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureRoutes() 0 7 1
A configureContainer() 0 13 1
A registerBundles() 0 6 4
A getLogDir() 0 3 1
A getCacheDir() 0 3 1
1
<?php
2
3
namespace FabienCrassat\CurriculumVitaeBundle\Test;
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
    const TEST_FOLDER = '/Tests/Fixtures/App';
18
19
    public function getCacheDir()
20
    {
21
        return $this->getProjectDir().self::TEST_FOLDER.'/var/cache/'.$this->environment;
22
    }
23
24
    public function getLogDir()
25
    {
26
        return $this->getProjectDir().self::TEST_FOLDER.'/var/log';
27
    }
28
29
    public function registerBundles()
30
    {
31
        $contents = require $this->getProjectDir().self::TEST_FOLDER.'/config/bundles.php';
32
        foreach ($contents as $class => $envs) {
33
            if (isset($envs['all']) || isset($envs[$this->environment])) {
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 iterable|Symfony\Compone...undle\BundleInterface[].

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
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
40
    {
41
        $container->addResource(new FileResource($this->getProjectDir().self::TEST_FOLDER.'/config/bundles.php'));
42
        // Feel free to remove the "container.autowiring.strict_mode" parameter
43
        // if you are using symfony/dependency-injection 4.0+ as it's the default behavior
44
        $container->setParameter('container.autowiring.strict_mode', true);
45
        $container->setParameter('container.dumper.inline_class_loader', true);
46
        $confDir = $this->getProjectDir().self::TEST_FOLDER.'/config';
47
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
    protected function configureRoutes(RouteCollectionBuilder $routes)
55
    {
56
        $confDir = $this->getProjectDir().self::TEST_FOLDER.'/config';
57
58
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
59
        $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
60
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
61
    }
62
}
63