DebugCompilerPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 17
ccs 10
cts 10
cp 1
crap 2
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PanicLabCore\DependencyInjection;
6
7
use PanicLabCore\Services\CalcService;
8
use PanicLabCore\Services\Debug\DebugCalcService;
9
use PanicLabCore\Services\Debug\Log\DebugLogger;
10
use PanicLabCore\Services\Handlers\TileHandlerCollector;
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Definition;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
class DebugCompilerPass implements CompilerPassInterface
17
{
18
    /** @var string */
19
    private $environment;
20
21 3
    public function __construct(string $environment)
22
    {
23 3
        $this->environment = $environment;
24 3
    }
25
26
    /**
27
     * Overwrites the `CalcService` with its respective debug version `DebugCalcService`
28
     */
29 3
    public function process(ContainerBuilder $container): void
30
    {
31 3
        if ($this->environment !== 'dev') {
32 2
            return;
33
        }
34
35 1
        $serviceId = CalcService::class;
36 1
        $debugService = new Definition(
37 1
            DebugCalcService::class,
38
            [
39 1
                new Reference(DebugLogger::class),
40 1
                $container->getDefinition(TileHandlerCollector::class),
41 1
                $container->getParameter('max_steps'),
42
            ]
43
        );
44
45 1
        $container->setDefinition($serviceId, $debugService);
46 1
    }
47
}
48