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

ConsoleTarget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 29.73 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 11
loc 37
ccs 0
cts 18
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 6 2
A out() 11 11 2
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 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