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

MonologHandlerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 12
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 10 5
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