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

src/log/OldConsoleTarget.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Yii;
14
use yii\helpers\Console;
15
use yii\log\Logger;
16
17
class OldConsoleTarget extends \yii\log\Target
18
{
19
    public $exportInterval = 1;
20
21
    public static $styles = [
22
        Logger::LEVEL_WARNING => [Console::FG_YELLOW],
23
        Logger::LEVEL_ERROR   => [Console::FG_RED],
24
    ];
25
26
    public function export()
27
    {
28
        foreach ($this->messages as $message) {
29
            $this->out($message[0], $message[1]);
30
        }
31
    }
32
33 View Code Duplication
    public function out($message, $level)
0 ignored issues
show
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...
34
    {
35
        if ($level > $this->getLevel()) {
36
            return;
37
        }
38
        $style = self::$styles[$level];
39
        if ($style) {
40
            $message = Console::ansiFormat($message, $style);
41
        }
42
        Console::stdout($message . "\n");
43
    }
44
45
    public function getLevel()
46
    {
47
        return Yii::$app->get('log')->getLevel();
48
    }
49
50
    protected function getContextMessage()
51
    {
52
        return '';
53
    }
54
}
55