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.

SlackLoggerServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 101
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A register() 0 54 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\SlackHandler;
9
10
class SlackLoggerServiceProvider implements ServiceProviderInterface
11
{
12
13
    /**
14
     * @var string
15
     */
16
    public $token;
17
18
    /**
19
     * @var string
20
     */
21
    public $channel;
22
23
    /**
24
     * @var string
25
     */
26
    public $username;
27
28
    /**
29
     * @var int
30
     */
31
    public $loglevel = Logger::CRITICAL;
32
33
34
    /**
35
     * @param string   $token    Slack token
36
     * @param string   $channel  Slack channel
37
     * @param string   $username Slack username
38
     * @param int|null $loglevel Monolog Loglevel constant
39
     */
40 6
    public function __construct(string $token, string $channel, string $username, int $loglevel = null)
41
    {
42 6
        $this->token    = $token;
43 6
        $this->channel  = $channel;
44 6
        $this->username = $username;
45
46 6
        if (!is_null($loglevel)) {
47 6
            $this->loglevel = $loglevel;
48
        }
49 6
    }
50
51
52
    /**
53
     * @param  Container $dic [description]
54
     * @return void
55
     */
56 4
    public function register(Container $dic)
57
    {
58
59
60
        // Make sure there's a 'Monolog.Handlers' service
61 4
        if (!$dic->offsetExists('Monolog.Handlers')) :
62 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...
63 2
                return array();
64
            };
65
        endif;
66
67
68
        /**
69
         * @return array
70
         */
71 4
        $dic->extend('Monolog.Handlers', function (array $handlers, $dic) {
72 2
            $handlers[] = $dic['Monolog.Handlers.SlackHandler'];
73 2
            return $handlers;
74 4
        });
75
76
77
78
        /**
79
         * Send log messages to Slack.
80
         *
81
         * - https://blog.tschelhas.de/symfony/slack-als-logger-fuer-symfony-nutzen/
82
         * - https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/SlackHandler.php
83
         *
84
         * @return SlackHandler
85
         */
86 4
        $dic['Monolog.Handlers.SlackHandler'] = 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...
87
88
            // As hardcoded in SlackHandler class
89 4
            $useAttachment          = true;              // Whether the message should be added to Slack as attachment (plain text otherwise)
90 4
            $iconEmoji              = null;              // The emoji name to use (or null)
91 4
            $loglevel               = Logger::CRITICAL;  // The minimum logging level at which this handler will be triggered
0 ignored issues
show
Unused Code introduced by
$loglevel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92 4
            $bubble                 = true;              // Whether the messages that are handled can bubble up the stack or not
93 4
            $useShortAttachment     = false;             // Whether the the context/extra messages added to Slack as attachments are in a short style
0 ignored issues
show
Unused Code introduced by
$useShortAttachment is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
94 4
            $includeContextAndExtra = false;             // Whether the attachment should include context and extra data
0 ignored issues
show
Unused Code introduced by
$includeContextAndExtra is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
95 4
            $excludeFields          = array();           // Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
96
97
            // Override with custom values
98 4
            $loglevel               = $this->loglevel;   // Override for custom loglevel
99 4
            $includeContextAndExtra = true;              // Show details in Slack
100 4
            $useShortAttachment     = true;              // Show details in Slack as compact JSON code boxes
101
102
            // Slack credentials
103 4
            $token    = $this->token;
104 4
            $channel  = $this->channel;
105 4
            $username = $this->username;
106
107 4
            return new SlackHandler($token, $channel, $username, $useAttachment, $iconEmoji, $loglevel, $bubble, $useShortAttachment, $includeContextAndExtra, $excludeFields);
108
        };
109 4
    }
110
}
111