Log::process()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 13
nc 4
nop 1
crap 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