AppKernel   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 4

Test Coverage

Coverage 72%

Importance

Changes 0
Metric Value
wmc 14
lcom 4
cbo 4
dl 0
loc 131
ccs 36
cts 50
cp 0.72
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addBundle() 0 4 1
A addConfigFile() 0 4 1
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A getProjectDir() 0 8 2
A setRootDir() 0 4 1
A setProjectDir() 0 4 1
A registerBundles() 0 10 2
A registerContainerConfiguration() 0 18 2
A loadRoutes() 0 7 1
1
<?php
2
3
namespace Nyholm\BundleTest;
4
5
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\HttpKernel\Kernel;
9
use Symfony\Component\Routing\RouteCollectionBuilder;
10
11
/**
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class AppKernel extends Kernel
15
{
16
    /**
17
     * @var string[]
18
     */
19
    private $bundlesToRegister = [];
20
21
    /**
22
     * @var array
23
     */
24
    private $configFiles = [];
25
26
    /**
27
     * @var string
28
     */
29
    private $cachePrefix = '';
30
31
    /**
32
     * @var string|null;
33
     */
34
    private $fakedProjectDir;
35
36
    /**
37
     * @param string $cachePrefix
38
     */
39 1
    public function __construct($cachePrefix)
40
    {
41 1
        parent::__construct($cachePrefix, true);
42 1
        $this->cachePrefix = $cachePrefix;
43 1
        $this->addBundle(FrameworkBundle::class);
44 1
        $this->addConfigFile(__DIR__.'/config/framework.yml');
45 1
    }
46
47
    /**
48
     * @param string $bundle
0 ignored issues
show
Documentation introduced by
There is no parameter named $bundle. Did you maybe mean $bundleClassName?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
49
     */
50 1
    public function addBundle($bundleClassName)
51
    {
52 1
        $this->bundlesToRegister[] = $bundleClassName;
53 1
    }
54
55
    /**
56
     * @param string $configFile path to config file
57
     */
58 1
    public function addConfigFile($configFile)
59
    {
60 1
        $this->configFiles[] = $configFile;
61 1
    }
62
63 1
    public function getCacheDir()
64
    {
65 1
        return sys_get_temp_dir().'/NyholmBundleTest/'.$this->cachePrefix;
66
    }
67
68 1
    public function getLogDir()
69
    {
70 1
        return sys_get_temp_dir().'/NyholmBundleTest/log';
71
    }
72
73
    public function getProjectDir()
74
    {
75
        if (null === $this->fakedProjectDir) {
76
            return realpath(__DIR__.'/../../../../');
77
        }
78
79
        return $this->fakedProjectDir;
80
    }
81
82
    /**
83
     * @param string|null $rootDir
84
     */
85
    public function setRootDir($rootDir)
86
    {
87
        $this->rootDir = $rootDir;
88
    }
89
90
    /**
91
     * @param string|null $projectDir
92
     */
93
    public function setProjectDir($projectDir)
94
    {
95
        $this->fakedProjectDir = $projectDir;
96
    }
97
98 1
    public function registerBundles()
99
    {
100 1
        $this->bundlesToRegister = array_unique($this->bundlesToRegister);
101 1
        $bundles = [];
102 1
        foreach ($this->bundlesToRegister as $bundle) {
103 1
            $bundles[] = new $bundle();
104 1
        }
105
106 1
        return $bundles;
107
    }
108
109
    /**
110
     * (From MicroKernelTrait)
111
     * {@inheritdoc}
112
     */
113
    public function registerContainerConfiguration(LoaderInterface $loader)
114
    {
115 1
        $loader->load(function (ContainerBuilder $container) use ($loader) {
116 1
            $container->loadFromExtension('framework', [
117
                'router' => [
118 1
                    'resource' => 'kernel:loadRoutes',
119 1
                    'type' => 'service',
120 1
                ],
121 1
            ]);
122
123 1
            $this->configFiles = array_unique($this->configFiles);
124 1
            foreach ($this->configFiles as $path) {
125 1
                $loader->load($path);
126 1
            }
127
128 1
            $container->addObjectResource($this);
129 1
        });
130 1
    }
131
132
    /**
133
     * (From MicroKernelTrait).
134
     *
135
     * @internal
136
     */
137
    public function loadRoutes(LoaderInterface $loader)
138
    {
139
        $routes = new RouteCollectionBuilder($loader);
140
        $routes->import(__DIR__.'/config/routing.yml');
141
142
        return $routes->build();
143
    }
144
}
145