GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LoggerServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 136
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 4
B register() 0 102 1
1
<?php
2
namespace Germania\Logger;
3
4
use Pimple\Container;
5
use Pimple\ServiceProviderInterface;
6
7
use Psr\Log\LoggerInterface;
8
use Monolog\Logger as MonologLogger;
9
use Monolog\Processor\WebProcessor;
10
use Monolog\Processor\PsrLogMessageProcessor;
11
12
class LoggerServiceProvider implements ServiceProviderInterface
13
{
14
15
    /**
16
     * @var string
17
     */
18
    public $logger_name  = "Logger";
19
20
    /**
21
     * @var array
22
     */
23
    public $server_data  = array();
24
25
26
    /**
27
     * @param string   $logger_name   App or logger name
28
     * @param array    $server_data   Server data, default is `$_SERVER`
29
     * @param boolean  $anonymize_ip  Whether to anonymize client IPs
30
     */
31 18
    public function __construct(string $logger_name, array $server_data = null, $anonymize_ip = true)
32
    {
33 18
        $this->logger_name  = $logger_name;
34 18
        $this->server_data  = $server_data ?: $_SERVER;
35
36 18
        if ($anonymize_ip and isset($this->server_data['REMOTE_ADDR'])):
37 2
            $this->server_data['REMOTE_ADDR'] = preg_replace('/[0-9]+\z/', 'XXX', $this->server_data['REMOTE_ADDR']);
38
        endif;
39 18
    }
40
41
42
    /**
43
     * @return void
44
     */
45 10
    public function register(Container $dic)
46
    {
47
48
49
        /**
50
         * @return \Monolog\Logger
51
         */
52 10
        $dic[LoggerInterface::class] = function ($dic) {
53 2
            return $dic['Monolog.Psr3Logger'];
54
        };
55
56
57
58
        /**
59
         * @return \Monolog\Logger
60
         */
61 10
        $dic['Logger'] = function ($dic) {
62 2
            return $dic['Monolog.Psr3Logger'];
63
        };
64
65
66
67
        /**
68
         * @return string
69
         */
70 10
        $dic['Logger.name'] = function ($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic 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...
71 6
            return $this->logger_name;
72
        };
73
74
75
        /**
76
         * @return array
77
         */
78 10
        $dic['Logger.Environment'] = function ($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic 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...
79 8
            return $this->server_data;
80
        };
81
82
83
        /**
84
         * @return MonologLogger
85
         */
86 10
        $dic['Monolog.Psr3Logger'] = function ($dic) {
87 6
            $handlers   = $dic['Monolog.Handlers'];
88 6
            $processors = $dic['Monolog.Processors'];
89 6
            $title      = $dic['Logger.name'];
90
91 6
            return new MonologLogger($title, $handlers, $processors);
92
        };
93
94
95
        /**
96
         * @return array
97
         */
98 10
        $dic['Monolog.Handlers'] = function ($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic 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...
99 8
            return array();
100
        };
101
102
103
104
        /**
105
         * @return array
106
         */
107 10
        $dic['Monolog.Processors'] = function ($dic) {
108
            return array(
109 8
                $dic['Monolog.Processors.PsrLogMessages'],
110 8
                $dic['Monolog.Processors.WebProcessor']
111
            );
112
        };
113
114
115
        /**
116
         * @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/PsrLogMessageProcessor.php
117
         * @return PsrLogMessageProcessor
118
         */
119 10
        $dic['Monolog.Processors.PsrLogMessages'] = function ($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic 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...
120 8
            return new PsrLogMessageProcessor(null, true);
121
        };
122
123
124
        /**
125
         * @return WebProcessor
126
         */
127 10
        $dic['Monolog.Processors.WebProcessor'] = function ($dic) {
128 8
            $server_data  = $dic['Logger.Environment'];
129 8
            $extra_fields = $dic['Monolog.Processors.WebProcessor.extraFields'];
130 8
            return new WebProcessor($server_data, $extra_fields);
131
        };
132
133
134
        /**
135
         * Choose from url, ip, http_method, server, referrer
136
         *
137
         * @return array
138
         */
139 10
        $dic['Monolog.Processors.WebProcessor.extraFields'] = function ($dic) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic 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...
140
            return [
141 8
                'http_method',
142
                'url',
143
                'ip'
144
            ];
145
        };
146 10
    }
147
}
148