Completed
Push — master ( 20183c...a5ea1d )
by Andrii
04:32
created

ConsoleTarget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 35.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 14
loc 39
ccs 0
cts 20
cp 0
rs 10

3 Methods

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

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 Psr\Log\LogLevel;
14
use yii\helpers\Console;
15
16
class ConsoleTarget extends \yii\log\Target
17
{
18
    public $exportInterval = 1;
19
20
    public static $styles = [
21
        LogLevel::EMERGENCY => [Console::FG_RED],
22
        LogLevel::ALERT     => [Console::FG_RED],
23
        LogLevel::CRITICAL  => [Console::FG_RED],
24
        LogLevel::ERROR     => [Console::FG_RED],
25
        LogLevel::WARNING   => [Console::FG_YELLOW],
26
    ];
27
28
    public function export()
29
    {
30
        foreach ($this->messages as $message) {
31
            $this->out($message[0], $message[1]);
32
        }
33
    }
34
35 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...
36
    {
37
        /* XXX add minimum log severity to show
38
         * if ($level > $this->getLevel()) {
39
            return;
40
        }*/
41
        $style = self::$styles[$level];
42
        if ($style) {
43
            $message = Console::ansiFormat($message, $style);
44
        } else {
45
            return;
46
        }
47
        Console::stdout($message . "\n");
48
    }
49
50
    protected function getContextMessage()
51
    {
52
        return '';
53
    }
54
}
55