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.

BrowserConsoleLoggerServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 57.89 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 33
loc 57
ccs 13
cts 17
cp 0.7647
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 33 33 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\Handler\BrowserConsoleHandler;
9
10
class BrowserConsoleLoggerServiceProvider implements ServiceProviderInterface
11
{
12
13
14
    /**
15
     * @var int
16
     */
17
    public $loglevel = Logger::INFO;
18
19
20
    /**
21
     * @param int|null $loglevel Optional: Monolog Loglevel constant. Set to `null` to disable browser logging entirely.
22
     */
23 2
    public function __construct(int $loglevel = null)
24
    {
25 2
        $this->loglevel = $loglevel;
26 2
    }
27
28
29
    /**
30
     * @param  Container $dic [description]
31
     * @return void
32
     */
33 2 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...
34
    {
35
        // Do nothing when no loglevel is set
36 2
        if (empty($this->loglevel)) {
37
            return;
38
        }
39
40
        // Make sure there's a 'Monolog.Handlers' service
41 2
        if (!$dic->offsetExists('Monolog.Handlers')) :
42 2
            $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...
43
                return array();
44
            };
45
        endif;
46
47
48
        /**
49
         * @return array
50
         */
51 2
        $dic->extend('Monolog.Handlers', function (array $handlers, $dic) {
52
            $handlers[] = $dic['Monolog.Handlers.BrowserConsoleHandler'];
53
            return $handlers;
54 2
        });
55
56
57
58
        /**
59
         * @return BrowserConsoleHandler
60
         */
61 2
        $dic['Monolog.Handlers.BrowserConsoleHandler'] = 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...
62 2
            $th = new BrowserConsoleHandler($this->loglevel);
63 2
            return $th;
64
        };
65 2
    }
66
}
67