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.

TeamsLoggerServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 55.88 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 38
loc 68
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A register() 38 38 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Germania\Logger;
3
4
use Pimple\Container;
5
use Pimple\ServiceProviderInterface;
6
7
use Monolog\Logger;
8
use Monolog\Formatter\HtmlFormatter;
9
use CMDISP\MonologMicrosoftTeams\TeamsLogHandler;
10
11
12
class TeamsLoggerServiceProvider implements ServiceProviderInterface
13
{
14
15
    /**
16
     * @var string
17
     */
18
    public $incoming_webook_url;
19
20
    /**
21
     * @var int
22
     */
23
    public $loglevel = Logger::INFO;
24
25
26
    /**
27
     * @param string   $incoming_webook_url Incoming Webhook URL, leave empty to disable
28 6
     * @param int|null $loglevel            Monolog loglevel number
29
     */
30 6
    public function __construct(string $incoming_webook_url = null, int $loglevel = null)
31 6
    {
32 6
        $this->incoming_webook_url = $incoming_webook_url;
33
        $this->loglevel = $loglevel ?: Logger::INFO;
34
    }
35
36
37
    /**
38
     * @param  Container $dic [description]
39 4
     * @return void
40
     */
41 View Code Duplication
    public function register(Container $dic)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43 4
44
        // Do nothing when no incoming_webook_url is set
45
        if (empty($this->incoming_webook_url)) {
46
            return;
47
        }
48
49 4
50 4
        // Make sure there's a 'Monolog.Handlers' service
51 2
        if (!$dic->offsetExists('Monolog.Handlers')) :
52
            $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...
53
                return array();
54
            };
55
        endif;
56
57
58
        /**
59 4
         * @return array
60 2
         */
61 2
        $dic->extend('Monolog.Handlers', function (array $handlers, $dic) {
62 4
            $handlers[] = $dic['Monolog.Handlers.TeamsHandler'];
63
            return $handlers;
64
        });
65
66
67
68
        /**
69
         * Send log messages to Microsoft Teams.
70
         *
71 4
         * @return SlackHandler
72 4
         */
73 4
        $dic['Monolog.Handlers.TeamsHandler'] = 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...
74 4
            $th = new TeamsLogHandler($this->incoming_webook_url, $this->loglevel);
75
            $th->setFormatter(new HtmlFormatter);
76 4
            return $th;
77
        };
78
    }
79
}
80