Passed
Push — master ( da9ebc...eab3b6 )
by Tobias
02:14
created

MonologHandlerPass::process()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\NewRelicBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
class MonologHandlerPass implements CompilerPassInterface
21
{
22
    public function process(ContainerBuilder $container): void
23
    {
24
        if (!$container->hasParameter('ekino.new_relic.monolog.channels') || !$container->hasDefinition('monolog.logger')) {
25
            return;
26
        }
27
28
        $channels = $container->getParameter('ekino.new_relic.monolog.channels');
29
        foreach ($channels as $channel) {
30
            $def = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel);
31
            $def->addMethodCall('pushHandler', [new Reference('ekino.new_relic.logs_handler')]);
32
        }
33
    }
34
}
35