Passed
Push — fix/logger ( 5937e6...7440b5 )
by Jérémy
03:24
created

LoggerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
rs 10
cc 3
nc 3
nop 1
crap 3.0261
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Thunder micro CLI framework.
7
 * (c) Jérémy Marodon <[email protected]>
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RxThunder\Core\Logger;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
final class LoggerPass implements CompilerPassInterface
19
{
20
    public const TAG = 'logger.aware';
21
22 3
    public function process(ContainerBuilder $container): void
23
    {
24 3
        if (!$container->hasDefinition('logger')) {
25
            return;
26
        }
27
28 3
        $tagged_services = $container->findTaggedServiceIds(self::TAG);
29
30 3
        foreach ($tagged_services as $id => $tags) {
31 1
            $definition = $container->findDefinition($id);
32 1
            $definition->addMethodCall('setLogger', [new Reference('logger')]);
33
        }
34 3
    }
35
}
36