Passed
Branch master (bbfb46)
by Jan
22:41 queued 14:44
created

TestKernel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getProjectDir() 0 15 4
A initializeFeatureFlags() 0 2 1
A initializePlugins() 0 4 1
A getContainer() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\System\Test\SystemConfig;
4
5
require_once __DIR__ . '/_fixtures/SwagExampleTest/SwagExampleTest.php';
6
require_once __DIR__ . '/_fixtures/SwagInvalidTest/SwagInvalidTest.php';
7
8
use Shopware\Core\Kernel;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
11
class TestKernel extends Kernel
12
{
13
    /**
14
     * @var string
15
     */
16
    private $projectDir;
17
18
    public function getProjectDir(): string
19
    {
20
        if ($this->projectDir === null) {
21
            $r = new \ReflectionClass($_SERVER['KERNEL_CLASS']);
22
            $dir = $rootDir = \dirname($r->getFileName());
23
            while (!file_exists($dir . '/composer.json')) {
24
                if ($dir === \dirname($dir)) {
25
                    return $this->projectDir = $rootDir;
26
                }
27
                $dir = \dirname($dir);
28
            }
29
            $this->projectDir = $dir;
30
        }
31
32
        return $this->projectDir;
33
    }
34
35
    /**
36
     * This results in the test container, with all private services public
37
     */
38
    public function getContainer(): ContainerInterface
39
    {
40
        return parent::getContainer();
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getContainer() could return the type null which is incompatible with the type-hinted return Symfony\Component\Depend...tion\ContainerInterface. Consider adding an additional type-check to rule them out.
Loading history...
41
    }
42
43
    protected function initializePlugins(): void
44
    {
45
        self::$plugins->add(new \SwagExampleTest\SwagExampleTest());
46
        self::$plugins->add(new \SwagInvalidTest\SwagInvalidTest());
47
    }
48
49
    protected function initializeFeatureFlags(): void
50
    {
51
        //empty body intended, to prevent duplicate registration of feature flags
52
    }
53
}
54