Test Setup Failed
Push — master ( 358c21...90dd8a )
by Dominik
01:57
created

MonologServiceProvider::translateLevel()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 0
cts 0
cp 0
rs 8.6845
cc 4
eloc 12
nc 4
nop 1
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Fabien Potencier <[email protected]> (https://github.com/silexphp/Silex-Providers)
7
 */
8
9
namespace Chubbyphp\ServiceProvider;
10
11
use Monolog\Formatter\LineFormatter;
12
use Monolog\Handler\GroupHandler;
13
use Monolog\Handler\StreamHandler;
14
use Monolog\Logger;
15
use Pimple\Container;
16
use Psr\Log\LogLevel;
17
18
final class MonologServiceProvider
19
{
20
    /**
21 1
     * @param Container $container
22 1
     */
23
    public function register(Container $container)
24
    {
25 1
        $container['logger'] = $this->getLoggerServiceDefinition($container);
26 1
        $container['monolog'] = $this->getMonologServiceDefinition($container);
27 1
        $container['monolog.formatter'] = $this->getMonologFormatterServiceDefinition($container);
28
        $container['monolog.default_handler'] = $this->getMonologDefaultHandlerServiceDefinition($container);
29 1
        $container['monolog.handlers'] = $this->getMonologHandlersServiceDefinition($container);
30
        $container['monolog.level'] = LogLevel::DEBUG;
31
        $container['monolog.name'] = 'app';
32 1
        $container['monolog.bubble'] = true;
33 1
        $container['monolog.permission'] = null;
34
    }
35
36 1
    /**
37 1
     * @param Container $container
38
     *
39 1
     * @return \Closure
40 1
     */
41 1
    private function getLoggerServiceDefinition(Container $container): \Closure
42 1
    {
43 1
        return function () use ($container) {
44
            return $container['monolog'];
45
        };
46 1
    }
47
48 1
    /**
49 1
     * @param Container $container
50
     *
51 1
     * @return \Closure
52 1
     */
53
    private function getMonologServiceDefinition(Container $container): \Closure
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55 1
        return function ($container) {
56 1
            $log = new Logger($container['monolog.name']);
57
            $log->pushHandler(new GroupHandler($container['monolog.handlers']));
58
59 1
            return $log;
60
        };
61
    }
62 1
63 1
    /**
64
     * @param Container $container
65
     *
66 1
     * @return \Closure
67 1
     */
68 1
    private function getMonologFormatterServiceDefinition(Container $container): \Closure
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69 1
    {
70
        return function () {
71
            return new LineFormatter();
72
        };
73
    }
74
75
    /**
76 1
     * @param Container $container
77
     *
78
     * @return \Closure
79 1
     */
80 1
    private function getMonologHandlersServiceDefinition(Container $container): \Closure
81
    {
82
        return function () use ($container) {
83
            return [$container['monolog.default_handler']];
84
        };
85
    }
86
87
    /**
88
     * @param Container $container
89
     *
90
     * @return \Closure
91
     */
92
    private function getMonologDefaultHandlerServiceDefinition(Container $container): \Closure
93
    {
94
        return function () use ($container) {
95
            $handler = new StreamHandler(
96
                $container['monolog.logfile'],
97
                $container['monolog.level'],
98
                $container['monolog.bubble'],
99
                $container['monolog.permission']
100
            );
101
102
            $handler->setFormatter($container['monolog.formatter']);
103
104
            return $handler;
105
        };
106
    }
107
}
108