Completed
Push — master ( 030030...90a95a )
by Matze
10:56 queued 07:21
created

LoggerCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 0 Features 3
Metric Value
wmc 4
c 11
b 0
f 3
lcom 0
cbo 3
dl 0
loc 36
ccs 17
cts 17
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 29 4
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use BrainExe\Core\Logger\ChannelStreamHandler;
7
use Monolog\Handler\ChromePHPHandler;
8
use Monolog\Handler\HipChatHandler;
9
use Monolog\Handler\StreamHandler;
10
use Monolog\Handler\TestHandler;
11
use Monolog\Logger;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Definition;
15
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
16
17
/**
18
 * @CompilerPass
19
 */
20
class LoggerCompilerPass implements CompilerPassInterface
21
{
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 4
    public function process(ContainerBuilder $container)
27
    {
28 4
        $logger = $container->getDefinition('logger');
29
30 4
        if ($container->getParameter('debug')) {
31 1
            $logger->addMethodCall('pushHandler', [new Definition(ChromePHPHandler::class)]);
32 1
            $logger->addMethodCall('pushHandler', [
33 1
                new Definition(StreamHandler::class, ['php://stdout', Logger::INFO])
34
            ]);
35
        }
36
37 4
        if ($container->getParameter('hipchat.api_token')) {
38 1
            $logger->addMethodCall('pushHandler', [new Definition(HipChatHandler::class, [
39 1
                $container->getParameter('hipchat.api_token'),
40 1
                $container->getParameter('hipchat.room'),
41 1
                $container->getParameter('hipchat.name'),
42
                false,
43 1
                $container->getParameter('hipchat.logLevel'),
44
            ])]);
45
        }
46
47 4
        foreach ($container->getParameter('logger.channels') as $config) {
48 2
            $logger->addMethodCall('pushHandler', [new Definition(ChannelStreamHandler::class, $config)]);
49
        }
50
51
        /** @var ParameterBag $parameterBag */
52 4
        $parameterBag = $container->getParameterBag();
53 4
        $parameterBag->remove('logger.channels');
54 4
    }
55
}
56