Completed
Push — master ( 3a0746...59d45e )
by Tobias
03:43
created

AppKernel::getProjectDir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
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
        $this->addBundle(FrameworkBundle::class);
44
        $this->addConfigFile(__DIR__.'/config/framework.yml');
45
    }
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
    public function addBundle($bundleClassName)
51
    {
52
        $this->bundlesToRegister[] = $bundleClassName;
53
    }
54
55
    /**
56
     * @param string $configFile path to config file
57
     */
58
    public function addConfigFile($configFile)
59
    {
60
        $this->configFiles[] = $configFile;
61
    }
62
63
    public function getCacheDir()
64
    {
65
        return sys_get_temp_dir().'/NyholmBundleTest/'.$this->cachePrefix;
66
    }
67
68
    public function getLogDir()
69
    {
70
        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
    public function registerBundles()
99
    {
100
        $this->bundlesToRegister = array_unique($this->bundlesToRegister);
101
        $bundles = [];
102
        foreach ($this->bundlesToRegister as $bundle) {
103
            $bundles[] = new $bundle();
104
        }
105
106
        return $bundles;
107
    }
108
109
    /**
110
     * (From MicroKernelTrait)
111
     * {@inheritdoc}
112
     */
113
    public function registerContainerConfiguration(LoaderInterface $loader)
114
    {
115
        $loader->load(function (ContainerBuilder $container) use ($loader) {
116
            $container->loadFromExtension('framework', [
117
                'router' => [
118
                    'resource' => 'kernel:loadRoutes',
119
                    'type' => 'service',
120
                ],
121
            ]);
122
123
            $this->configFiles = array_unique($this->configFiles);
124
            foreach ($this->configFiles as $path) {
125
                $loader->load($path);
126
            }
127
128
            $container->addObjectResource($this);
129
        });
130
    }
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