Passed
Branch v0.2 (3b8de8)
by Freddie
05:06
created

Bootstrap::getCompiledContainerDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Simplex;
4
5
use DI\Container;
6
use DI\ContainerBuilder as PHPDIContainerBuilder;
7
use Simplex\DefinitionLoader\ChainDefinitionLoader;
8
use Simplex\DefinitionLoader\ConfigDefinitionLoader;
9
use Simplex\DefinitionLoader\CoreDefinitionLoader;
10
use Simplex\DefinitionLoader\ModuleDefinitionLoader;
11
12
class Bootstrap
13
{
14
    /** @var Container */
15
    private static $container;
16
17
    public static function init(string $configDirectoryPath): void
18
    {
19
        $configDirectory = new \SplFileInfo($configDirectoryPath);
20
21
        $environment = new Environment();
22
        $environment->load($configDirectory);
23
24
        $definitionLoader = new ChainDefinitionLoader(
25
            new CoreDefinitionLoader(),
0 ignored issues
show
Bug introduced by
new Simplex\DefinitionLo...\CoreDefinitionLoader() of type Simplex\DefinitionLoader\CoreDefinitionLoader is incompatible with the type Simplex\DefinitionLoader\DefinitionLoader[] expected by parameter $loaders of Simplex\DefinitionLoader...onLoader::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            /** @scrutinizer ignore-type */ new CoreDefinitionLoader(),
Loading history...
26
            new ModuleDefinitionLoader($configDirectory),
0 ignored issues
show
Bug introduced by
new Simplex\DefinitionLo...oader($configDirectory) of type Simplex\DefinitionLoader\ModuleDefinitionLoader is incompatible with the type Simplex\DefinitionLoader\DefinitionLoader[] expected by parameter $loaders of Simplex\DefinitionLoader...onLoader::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
            /** @scrutinizer ignore-type */ new ModuleDefinitionLoader($configDirectory),
Loading history...
27
            new ConfigDefinitionLoader($configDirectory, $environment->getSimplexEnvironment())
0 ignored issues
show
Bug introduced by
new Simplex\DefinitionLo...etSimplexEnvironment()) of type Simplex\DefinitionLoader\ConfigDefinitionLoader is incompatible with the type Simplex\DefinitionLoader\DefinitionLoader[] expected by parameter $loaders of Simplex\DefinitionLoader...onLoader::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            /** @scrutinizer ignore-type */ new ConfigDefinitionLoader($configDirectory, $environment->getSimplexEnvironment())
Loading history...
28
        );
29
30
        $containerBuilder = new ContainerBuilder(
31
            $configDirectory,
32
            new PHPDIContainerBuilder(),
33
            $definitionLoader,
34
            $environment->getSimplexEnvironment()
35
        );
36
37
        if ($environment->getCompileContainer()) {
38
39
            $compiledContainerDirectory = self::getCompiledContainerDirectory();
40
            $containerBuilder->enableCompilation($compiledContainerDirectory);
41
        }
42
43
        self::$container = $containerBuilder->build();
44
    }
45
46
    private static function getCompiledContainerDirectory(): \SplFileInfo
47
    {
48
        return new \SplFileInfo(
49
            CACHE_DIRECTORY
50
            . DIRECTORY_SEPARATOR
51
            . ContainerBuilder::COMPILED_CONTAINER_DIRECTORY_NAME
52
        );
53
    }
54
55
    public static function getContainer(): Container
56
    {
57
        return self::$container;
58
    }
59
}
60