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

OldConsoleTarget   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 28.95 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 3
dl 11
loc 38
ccs 0
cts 25
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 6 2
A out() 11 11 3
A getLevel() 0 4 1
A getContextMessage() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
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...
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