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

PHPLog   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B log() 0 23 10
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