Label   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 24.14 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
A cssClasses() 7 7 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
 * HiPanel tickets module
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-ticket
6
 * @package   hipanel-module-ticket
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\ticket\widgets;
12
13
use yii\helpers\Html;
14
use yii\jui\Widget;
15
16
class Label extends Widget
17
{
18
    public $rules = [
19
        'priority' => ['medium' => 'info', 'high' => 'warning'],
20
        'state'    => ['opened' => 'success'],
21
    ];
22
23
    public $label;
24
25
    public $value;
26
27
    public $type;
28
29
    public $defaultCssClass = 'default';
30
31
    public function init()
32
    {
33
        parent::init();
34
        echo Html::tag('span', $this->label, ['class' => 'label label-' . $this->cssClasses()]);
35
    }
36
37 View Code Duplication
    protected function cssClasses()
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...
38
    {
39
        $t = mb_strtolower($this->type);
40
        $v = mb_strtolower($this->value);
41
42
        return (array_key_exists($v, $this->rules[$t])) ? $this->rules[$t][$v] : $this->defaultCssClass;
43
    }
44
}
45