Completed
Push — master ( f6cc4f...20183c )
by Andrii
03:46
created

ConsoleTarget::getLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\log;
12
13
use Psr\Log\LogLevel;
14
use Yii;
15
use yii\helpers\Console;
16
use yii\log\Logger;
17
18
class ConsoleTarget extends \yii\log\Target
19
{
20
    public $exportInterval = 1;
21
22
    public static $styles = [
23
        LogLevel::EMERGENCY => [Console::FG_RED],
24
        LogLevel::ALERT     => [Console::FG_RED],
25
        LogLevel::CRITICAL  => [Console::FG_RED],
26
        LogLevel::ERROR     => [Console::FG_RED],
27
        LogLevel::WARNING   => [Console::FG_YELLOW],
28
        LogLevel::NOTICE    => [Console::FG_YELLOW],
29
    ];
30
31
    public function export()
32
    {
33
        foreach ($this->messages as $message) {
34
            $this->out($message[0], $message[1]);
35
        }
36
    }
37
38 View Code Duplication
    public function out($level, $message)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        /*if ($level > $this->getLevel()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
            return;
42
        }*/
43
        $style = self::$styles[$level];
44
        if ($style) {
45
            $message = Console::ansiFormat($message, $style);
46
        }
47
        Console::stdout($message . "\n");
48
    }
49
50
    protected function getContextMessage()
51
    {
52
        return '';
53
    }
54
}
55