StdoutTarget   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B export() 0 22 6
1
<?php
2
/**
3
 * Asset Packagist.
4
 *
5
 * @link      https://github.com/hiqdev/asset-packagist
6
 * @package   asset-packagist
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\assetpackagist\log;
12
13
use yii\helpers\Console;
14
use yii\helpers\VarDumper;
15
use yii\log\Logger;
16
use yii\log\Target;
17
18
class StdoutTarget extends Target
19
{
20
    /**
21
     * Exports log [[messages]] to a specific destination.
22
     * Child classes must implement this method.
23
     */
24
    public function export()
25
    {
26
        foreach ($this->messages as $message) {
27
            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...
28
            if (!is_string($text)) {
29
                // exceptions may not be serializable if in the call stack somewhere is a Closure
30
                if ($text instanceof \Throwable || $text instanceof \Exception) {
31
                    $text = (string) $text;
32
                } else {
33
                    $text = VarDumper::export($text);
34
                }
35
            }
36
37
            $string = "[$level][$category] $text";
38
39
            if ($level === Logger::LEVEL_ERROR) {
40
                Console::stderr($string);
41
            } else {
42
                Console::stdout($string);
43
            }
44
        }
45
    }
46
}
47