Completed
Push — master ( e3b8a9...e92bf7 )
by huang
05:36
created

Logger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertStatusCodeToLevel() 0 4 3
A addRecord() 0 8 2
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\Logger;
11
12
use Monolog\Handler\StreamHandler;
13
use Monolog\Logger as MonoLogger;
14
15
/**
16
 * Class Logger.
17
 */
18
class Logger extends MonoLogger
19
{
20
    /**
21
     * @param $levelCode
22
     *
23
     * @return int
24
     */
25 9
    protected function convertStatusCodeToLevel($levelCode)
26
    {
27 9
        return ($levelCode >= 200 && $levelCode < 300) ? self::INFO : self::ERROR;
28
    }
29
30
    /**
31
     * @param int    $level
32
     * @param string $message
33
     * @param array  $context
34
     *
35
     * @return bool
36
     */
37 9
    public function addRecord($level, $message, array $context = array())
38
    {
39 9
        if (!$this->handlers) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->handlers of type Monolog\Handler\HandlerInterface[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
40 2
            $this->pushHandler(new StreamHandler('php://temp'));
41 2
        }
42
43 9
        return parent::addRecord($this->convertStatusCodeToLevel($level), $message, $context);
44
    }
45
}
46