AppKernel   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 12
c 2
b 0
f 1
lcom 2
cbo 3
dl 0
loc 66
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A registerBundles() 0 8 2
A getRootDir() 0 4 1
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A registerContainerConfiguration() 0 4 1
A serialize() 0 4 1
A unserialize() 0 5 1
A getKernelParameters() 0 7 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 47 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[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
namespace TwoMartens\Bundle\CoreBundle\Tests\Functional\app;
13
14
// get the autoload file
15
$dir = __DIR__;
16
$lastDir = null;
17
while ($dir !== $lastDir) {
18
    $lastDir = $dir;
19
20
    if (file_exists($dir.'/autoload.php')) {
21
        require_once $dir.'/autoload.php';
22
        break;
23
    }
24
25
    if (file_exists($dir.'/autoload.php.dist')) {
26
        require_once $dir.'/autoload.php.dist';
27
        break;
28
    }
29
30
    if (file_exists($dir.'/vendor/autoload.php')) {
31
        require_once $dir.'/vendor/autoload.php';
32
        break;
33
    }
34
35
    $dir = dirname($dir);
36
}
37
38
use Symfony\Component\Config\Loader\LoaderInterface;
39
use Symfony\Component\Filesystem\Filesystem;
40
use Symfony\Component\HttpKernel\Kernel;
41
42
/**
43
 * App Test Kernel for functional tests.
44
 *
45
 * @author Johannes M. Schmitt <[email protected]>
46
 */
47
class AppKernel extends Kernel
48
{
49
    private $testCase;
50
    private $rootConfig;
51
52
    public function __construct($testCase, $rootConfig, $environment, $debug)
53
    {
54
        $this->testCase = $testCase;
55
56
        $fs = new Filesystem();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $fs. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
57
        if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/config/'.$rootConfig)) {
58
            throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
59
        }
60
        $this->rootConfig = $rootConfig;
61
62
        parent::__construct($environment, $debug);
63
    }
64
65
    public function registerBundles()
66
    {
67
        if (!file_exists($filename = $this->getRootDir().'/config/bundles.php')) {
68
            throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
69
        }
70
71
        return include $filename;
72
    }
73
74
    public function getRootDir()
75
    {
76
        return __DIR__;
77
    }
78
79
    public function getCacheDir()
80
    {
81
        return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
82
    }
83
84
    public function getLogDir()
85
    {
86
        return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
87
    }
88
89
    public function registerContainerConfiguration(LoaderInterface $loader)
90
    {
91
        $loader->load($this->rootConfig);
92
    }
93
94
    public function serialize()
95
    {
96
        return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
97
    }
98
99
    public function unserialize($str)
100
    {
101
        $a = unserialize($str);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
102
        $this->__construct($a[0], $a[1], $a[2], $a[3]);
103
    }
104
105
    protected function getKernelParameters()
106
    {
107
        $parameters = parent::getKernelParameters();
108
        $parameters['kernel.test_case'] = $this->testCase;
109
110
        return $parameters;
111
    }
112
}
113