Completed
Push — master ( f22a46...046041 )
by Patrick
02:27 queued 12s
created

PHPLog::log()   B

Complexity

Conditions 10
Paths 17

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 17
nop 3
dl 0
loc 23
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Flipside\Log;
3
4
class PHPLog extends LogService
5
{
6
    public function __construct($params=false)
7
    {
8
        parent::__construct($params);
9
    }
10
11
    public function log($level, $message, array $context = array())
12
    {
13
        $severity = $level;
0 ignored issues
show
Unused Code introduced by
$severity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
14
        switch($level)
15
        {
16
            case \Psr\Log\LogLevel::EMERGENCY:
17
            case \Psr\Log\LogLevel::ALERT:
18
            case \Psr\Log\LogLevel::CRITICAL:
19
            case \Psr\Log\LogLevel::ERROR:
20
            case \Psr\Log\LogLevel::WARNING:
21
            case \Psr\Log\LogLevel::NOTICE:
22
            case \Psr\Log\LogLevel::INFO:
23
            case \Psr\Log\LogLevel::DEBUG:
24
                break;
25
            default:
26
                throw new \Psr\Log\InvalidArgumentException('log function only accepts valid levels. Level was: '.$level);
27
        }
28
        if($this->shouldLog($level))
29
        {
30
            $newMessage = $this->interpolate($message, $context);
31
            error_log('['.$level.'] '.$newMessage);
32
        }
33
    }
34
}
35
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
36