Passed
Branch 3.1 (11462b)
by huang
05:13
created

LoggerServiceProvider::register()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 13
nc 10
nop 1
dl 0
loc 22
ccs 17
cts 17
cp 1
crap 6
rs 8.6737
c 1
b 0
f 0
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