Passed
Push — master ( 30f57b...f3320a )
by huang
02:57
created

LoggerServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 6
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 22 6
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      http://www.fast-d.cn/
8
 */
9
10
namespace FastD\ServiceProvider;
11
12
use FastD\Container\Container;
13
use FastD\Container\ServiceProviderInterface;
14
use Monolog\Formatter\LineFormatter;
15
use Monolog\Handler\StreamHandler;
16
use Monolog\Logger;
17
18
/**
19
 * Class LoggerServiceProvider.
20
 */
21
class LoggerServiceProvider implements ServiceProviderInterface
22
{
23
    /**
24
     * @param Container $container
25
     */
26 43
    public function register(Container $container)
27
    {
28 43
        $logger = new Logger(app()->getName());
29
30 43
        $handlers = config()->get('log');
31 43
        $path = app()->getPath().'/runtime/logs';
32
33 43
        if (empty($handlers)) {
34 9
            $logger->pushHandler(new StreamHandler('php://temp'), Logger::DEBUG);
0 ignored issues
show
Unused Code introduced by
The call to Logger::pushHandler() has too many arguments starting with \Monolog\Logger::DEBUG.

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...
35 9
        }
36
37 43
        foreach ($handlers as $handler) {
38 34
            list($handle, $name, $level, $format) = array_pad($handler, 4, null);
39 34
            if (is_string($handle)) {
40 34
                $handle = new $handle($path.'/'.$name, $level);
41 34
            }
42 34
            null !== $format && $handle->setFormatter(is_string($format) ? new LineFormatter($format) : $format);
43 34
            $logger->pushHandler($handle);
44 43
        }
45
46 43
        $container->add('logger', $logger);
47 43
    }
48
}
49