Passed
Push — master ( 5778d3...f5b0ef )
by Dominik
02:17
created

MonologServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 90
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 1
A getLoggerDefinition() 0 6 1
A getMonologDefinition() 0 9 1
A getMonologFormatterDefinition() 0 6 1
A getMonologHandlersDefinition() 0 6 1
A getMonologDefaultHandlerDefinition() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ServiceProvider\ServiceProvider;
6
7
use Monolog\Formatter\LineFormatter;
8
use Monolog\Handler\GroupHandler;
9
use Monolog\Handler\StreamHandler;
10
use Monolog\Logger;
11
use Pimple\Container;
12
use Psr\Log\LogLevel;
13
14
final class MonologServiceProvider
15
{
16
    /**
17
     * @param Container $container
18
     */
19 1
    public function register(Container $container)
20
    {
21 1
        $container['logger'] = $this->getLoggerDefinition($container);
22 1
        $container['monolog'] = $this->getMonologDefinition($container);
23 1
        $container['monolog.formatter'] = $this->getMonologFormatterDefinition($container);
24 1
        $container['monolog.default_handler'] = $this->getMonologDefaultHandlerDefinition($container);
25 1
        $container['monolog.handlers'] = $this->getMonologHandlersDefinition($container);
26 1
        $container['monolog.level'] = LogLevel::DEBUG;
27 1
        $container['monolog.name'] = 'app';
28 1
        $container['monolog.bubble'] = true;
29 1
        $container['monolog.permission'] = null;
30 1
    }
31
32
    /**
33
     * @param Container $container
34
     *
35
     * @return callable
36
     */
37
    private function getLoggerDefinition(Container $container): callable
38
    {
39 1
        return function () use ($container) {
40 1
            return $container['monolog'];
41 1
        };
42
    }
43
44
    /**
45
     * @param Container $container
46
     *
47
     * @return callable
48
     */
49
    private function getMonologDefinition(Container $container): callable
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...
50
    {
51 1
        return function ($container) {
52 1
            $log = new Logger($container['monolog.name']);
53 1
            $log->pushHandler(new GroupHandler($container['monolog.handlers']));
54
55 1
            return $log;
56 1
        };
57
    }
58
59
    /**
60
     * @param Container $container
61
     *
62
     * @return callable
63
     */
64
    private function getMonologFormatterDefinition(Container $container): callable
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...
65
    {
66 1
        return function () {
67 1
            return new LineFormatter();
68 1
        };
69
    }
70
71
    /**
72
     * @param Container $container
73
     *
74
     * @return callable
75
     */
76
    private function getMonologHandlersDefinition(Container $container): callable
77
    {
78 1
        return function () use ($container) {
79 1
            return [$container['monolog.default_handler']];
80 1
        };
81
    }
82
83
    /**
84
     * @param Container $container
85
     *
86
     * @return callable
87
     */
88
    private function getMonologDefaultHandlerDefinition(Container $container): callable
89
    {
90 1
        return function () use ($container) {
91 1
            $handler = new StreamHandler(
92 1
                $container['monolog.logfile'],
93 1
                $container['monolog.level'],
94 1
                $container['monolog.bubble'],
95 1
                $container['monolog.permission']
96
            );
97
98 1
            $handler->setFormatter($container['monolog.formatter']);
99
100 1
            return $handler;
101 1
        };
102
    }
103
}
104