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.

StreamLoggerServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 92
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 92
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
B register() 0 56 2
1
<?php
2
namespace Germania\Logger;
3
4
use Pimple\Container;
5
use Pimple\ServiceProviderInterface;
6
7
use Monolog\Logger;
8
use Monolog\Handler\StreamHandler;
9
use Bramus\Monolog\Formatter\ColoredLineFormatter;
10
11
class StreamLoggerServiceProvider implements ServiceProviderInterface
12
{
13
14
    /**
15
     * @var string
16
     */
17
    public $stream = "php://stderr";
18
19
20
    /**
21
     * @var int
22
     */
23
    public $loglevel = Logger::WARNING;
24
25
26
    /**
27
     * @param string|null $stream   PHP Stream name
28
     * @param int|null    $loglevel Monolog Loglevel constant
29
     */
30 6
    public function __construct(string $stream = null, int $loglevel = null)
31
    {
32 6
        if (!is_null($stream)) {
33 6
            $this->stream = $stream;
34
        }
35
36 6
        if (!is_null($loglevel)) {
37 6
            $this->loglevel = $loglevel;
38
        }
39 6
    }
40
41
42
    /**
43
     * @param  Container $dic [description]
44
     * @return void
45
     */
46 4
    public function register(Container $dic)
47
    {
48
49
50
51
        // Make sure there's a 'Monolog.Handlers' service
52 4
        if (!$dic->offsetExists('Monolog.Handlers')) :
53 4
            $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...
54 2
                return array();
55
            };
56
        endif;
57
58
59
        /**
60
         * @return array
61
         */
62 4
        $dic->extend('Monolog.Handlers', function (array $handlers, $dic) {
63 2
            $handlers[] = $dic['Monolog.Handlers.StreamHandler'];
64 2
            return $handlers;
65 4
        });
66
67
68
        /**
69
         * @return StreamHandler
70
         */
71 4
        $dic['Monolog.Handlers.StreamHandler'] = function ($dic) {
72 4
            $stream     = $this->stream;
73 4
            $loglevel   = $this->loglevel;
74
75 4
            $stream_handler = new StreamHandler($stream, $loglevel);
76
77 4
            $formatter = $dic['Monolog.Formatters.ColoredLineFormatter'];
78 4
            $stream_handler->setFormatter($formatter);
79
80 4
            return $stream_handler;
81
        };
82
83
84
        /**
85
         * Taken from Monolog
86
         */
87 4
        $dic['Monolog.Handlers.StreamHandler.FormatLine'] = 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...
88 4
            $format = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
89 4
            return $format;
90
        };
91
92
93
        /**
94
         * @see  https://github.com/bramus/monolog-colored-line-formatter/blob/master/src/Formatter/ColoredLineFormatter.php
95
         * @return  ColoredLineFormatter from Bramus
96
         */
97 4
        $dic['Monolog.Formatters.ColoredLineFormatter'] = function ($dic) {
98 4
            $format = $dic['Monolog.Handlers.StreamHandler.FormatLine'];
99 4
            return new ColoredLineFormatter(null, $format, null, false, "ignore_empty");
0 ignored issues
show
Documentation introduced by
'ignore_empty' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
        };
101 4
    }
102
}
103