Completed
Push — master ( 5a29a0...22ab66 )
by Dmitry
10:00
created

StdoutTarget   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B export() 0 22 6
1
<?php
2
3
namespace hiqdev\assetpackagist\log;
4
5
use yii\helpers\Console;
6
use yii\helpers\VarDumper;
7
use yii\log\Logger;
8
use yii\log\Target;
9
10
class StdoutTarget extends Target
11
{
12
    /**
13
     * Exports log [[messages]] to a specific destination.
14
     * Child classes must implement this method.
15
     */
16
    public function export()
17
    {
18
        foreach ($this->messages as $message) {
19
            list($text, $level, $category, $timestamp) = $message;
0 ignored issues
show
Unused Code introduced by
The assignment to $timestamp is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
20
            if (!is_string($text)) {
21
                // exceptions may not be serializable if in the call stack somewhere is a Closure
22
                if ($text instanceof \Throwable || $text instanceof \Exception) {
23
                    $text = (string)$text;
24
                } else {
25
                    $text = VarDumper::export($text);
26
                }
27
            }
28
29
            $string = "[$level][$category] $text";
30
31
            if ($level == Logger::LEVEL_ERROR) {
32
                Console::stderr($string);
33
            } else {
34
                Console::stdout($string);
35
            }
36
        }
37
    }
38
}
39