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.
Passed
Push — master ( b90f1e...f58393 )
by Carsten
03:32 queued 11s
created

TeamsLoggerServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 55.88 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
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
10
class TeamsLoggerServiceProvider implements ServiceProviderInterface
11
{
12
13
    /**
14
     * @var string
15
     */
16
    public $incoming_webook_url;
17
18
    /**
19
     * @var int
20
     */
21
    public $loglevel = Logger::INFO;
22
23
24
    /**
25
     * @param string   $incoming_webook_url Incoming Webhook URL, leave empty to disable
26
     * @param int|null $loglevel            Monolog loglevel number
27
     */
28 6
    public function __construct(string $incoming_webook_url = null, int $loglevel = null)
29
    {
30 6
        $this->incoming_webook_url = $incoming_webook_url;
31 6
        $this->loglevel = $loglevel ?: Logger::INFO;
32 6
    }
33
34
35
    /**
36
     * @param  Container $dic [description]
37
     * @return void
38
     */
39 4 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...
40
    {
41
42
        // Do nothing when no incoming_webook_url is set
43 4
        if (empty($this->incoming_webook_url)) {
44
            return;
45
        }
46
47
48
        // Make sure there's a 'Monolog.Handlers' service
49 4
        if (!$dic->offsetExists('Monolog.Handlers')) :
50 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...
51 2
                return array();
52
            };
53
        endif;
54
55
56
        /**
57
         * @return array
58
         */
59 4
        $dic->extend('Monolog.Handlers', function (array $handlers, $dic) {
60 2
            $handlers[] = $dic['Monolog.Handlers.TeamsHandler'];
61 2
            return $handlers;
62 4
        });
63
64
65
66
        /**
67
         * Send log messages to Microsoft Teams.
68
         *
69
         * @return SlackHandler
70
         */
71 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...
72 4
            $th = new HtmlFormattedTeamsLogHandler($this->incoming_webook_url, $this->loglevel);
73 4
            $th->setFormatter(new HtmlFormatter);
74 4
            return $th;
75
        };
76 4
    }
77
}
78