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

Logger::addRecord()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 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