Log   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 23 3
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use Monolog\Handler\StreamHandler;
7
use Monolog\Logger;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Definition;
11
12
/**
13
 * @CompilerPass
14
 */
15
class Log implements CompilerPassInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 1
    public function process(ContainerBuilder $container)
21
    {
22 1
        $definition = $container->getDefinition('logger');
23
24
        $logLevels = [
25 1
            'error.log' => Logger::ERROR,
26 1
            'info.log'  => Logger::INFO,
27
        ];
28
29 1
        if ($container->getParameter('debug')) {
30 1
            $logLevels['debug.log'] = Logger::DEBUG;
31
        }
32
33 1
        $baseDir = $container->getParameter('logger.dir');
34 1
        foreach ($logLevels as $file => $level) {
35 1
            $definition->addMethodCall('pushHandler', [
36 1
                new Definition(StreamHandler::class, [
37 1
                    $baseDir . $file,
38 1
                    $level
39
                ])
40
            ]);
41
        }
42 1
    }
43
}
44