Passed
Push — master ( 9478ec...26cf57 )
by Paweł
02:48
created

GameKernel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
c 1
b 0
f 0
dl 0
loc 44
ccs 20
cts 24
cp 0.8333
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpConsole() 0 4 1
A setUpContainer() 0 16 1
A runConsole() 0 3 1
A getContainer() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Infrastructure;
6
7
use AardsGerds\Game\Infrastructure\Cli\RunGameCommand;
8
use Symfony\Component\Config\FileLocator;
9
use Symfony\Component\Console\Application;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
12
13
final class GameKernel
14
{
15
    private ContainerBuilder $container;
16
    private Application $console;
17
18 2
    public function __construct(
19
        private string $environment,
20
    ) {
21 2
        $this->setUpContainer();
22 2
        $this->setUpConsole();
23 2
    }
24
25
    public function runConsole(): void
26
    {
27
        $this->console->run();
28
    }
29
30 2
    public function getContainer(): ContainerBuilder
31
    {
32 2
        return $this->container;
33
    }
34
35 2
    private function setUpContainer(): void
36
    {
37 2
        $this->container = new ContainerBuilder();
38 2
        $loader = new YamlFileLoader(
39 2
            $this->container,
40 2
            new FileLocator(dirname(__DIR__, 2) . '/config'),
41
        );
42
43 2
        $loader->load(match ($this->environment) {
44 2
            'test' => 'services_test.yaml',
45
            'prod' => 'services.yaml',
46 2
            default => throw GameKernelException::unknownEnvironment($this->environment),
47
        });
48
49 2
        $this->container->setParameter('kernel.project_dir', dirname(__DIR__, 2));
50 2
        $this->container->compile();
51 2
    }
52
53 2
    private function setUpConsole(): void
54
    {
55 2
        $this->console = new Application();
56 2
        $this->console->add(new RunGameCommand());
57 2
    }
58
}
59