Completed
Push — fix/logger ( 5937e6 )
by Jérémy
05:27
created

LoggerPassCompiler::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 4
cts 7
cp 0.5714
rs 10
cc 3
nc 3
nop 1
crap 3.7085
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RxThunder\Core\Compiler;
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
final class LoggerPassCompiler implements CompilerPassInterface
12
{
13
    public const TAG = 'logger.aware';
14
15 2
    public function process(ContainerBuilder $container): void
16
    {
17 2
        if (!$container->hasDefinition('logger')) {
18
            return;
19
        }
20
21 2
        $tagged_services = $container->findTaggedServiceIds(self::TAG);
22
23 2
        foreach ($tagged_services as $id => $tags) {
24
            $definition = $container->findDefinition($id);
25
            $definition->addMethodCall('setLogger', [new Reference('logger')]);
26
        }
27 2
    }
28
}
29