Completed
Push — staging ( 5f9089...8e7d49 )
by Matthew
04:33
created

LogServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 2
c 2
b 0
f 2
lcom 0
cbo 5
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 26 2
1
<?php
2
3
namespace Ps2alerts\Api\ServiceProvider;
4
5
use League\Container\ServiceProvider;
6
use Monolog\Logger;
7
use Monolog\Handler\StreamHandler;
8
use Monolog\Handler\SlackHandler;
9
10
class LogServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $provides = [
16
        'Monolog\Logger',
17
    ];
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function register()
23
    {
24
        $this->getContainer()->singleton('Monolog\Logger', function () {
25
            $log = new Logger('app');
26
27
            $config = $this->getContainer()->get('config');
28
29
            // Add slack for monitoring of critical errors
30
            if ($config['logger'] === 'slack') {
31
                $slackHandler = new SlackHandler(
32
                    $config['slack_api'],
33
                    $config['slack_channel'],
34
                    $config['slack_bot_name']
35
                );
36
                $slackHandler->setLevel(\Monolog\Logger::ERROR);
37
38
                $log->pushHandler($slackHandler, Logger::ERROR);
0 ignored issues
show
Unused Code introduced by
The call to Logger::pushHandler() has too many arguments starting with \Monolog\Logger::ERROR.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
            }
40
41
            $log->pushHandler(
42
                new StreamHandler(__DIR__ . '/../../logs/app.log', Logger::DEBUG)
43
            );
44
45
            return $log;
46
        });
47
    }
48
}
49