CLILogger   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B log() 0 26 4
1
<?php
2
namespace Buttress\IRC\Logger;
3
4
use Psr\Log\AbstractLogger;
5
use Psr\Log\LogLevel;
6
7
class CLILogger extends AbstractLogger
8
{
9
10
    protected $debug;
11
12
    function __construct($debug = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
13
    {
14
        $this->debug = !!$debug;
15
    }
16
17
    /**
18
     * Logs with an arbitrary level.
19
     *
20
     * @param mixed  $level
21
     * @param string $message
22
     * @param array  $context
23
     * @return null
24
     */
25
    public function log($level, $message, array $context = array())
26
    {
27
        $stamp = date("[Y-m-d H:i:s] ");
28
        $output = "";
29
30
        $message = trim($message);
31
32
        switch ($level) {
33
            case LogLevel::DEBUG:
34
                if ($this->debug) {
35
                    $output = "{$stamp} {$message}";
36
                }
37
                break;
38
39
            default:
40
                $output = "{$stamp} {$message}";
41
                break;
42
        }
43
44
        echo $output . PHP_EOL;
45
46
        if ($context) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $context of type array 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...
47
            var_dump($context);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($context); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
48
            echo PHP_EOL;
49
        }
50
    }
51
52
}
53