BillHwPurchaseCombo   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 41.51 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 22
loc 53
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilter() 0 7 1
A getPluginOptions() 22 22 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
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\widgets\combo;
12
13
use hiqdev\combo\Combo;
14
use yii\helpers\ArrayHelper;
15
use yii\web\JsExpression;
16
17
class BillHwPurchaseCombo extends Combo
18
{
19
    /** {@inheritdoc} */
20
    public $type = 'bill/descr';
21
22
    /** {@inheritdoc} */
23
    public $name = 'descr';
24
25
    /** {@inheritdoc} */
26
    public $url = '/finance/bill/index';
27
28
    /** {@inheritdoc} */
29
    public $_return = ['id', 'client', 'sum', 'currency', 'descr', 'label', 'time'];
30
31
    /** {@inheritdoc} */
32
    public $_rename = ['text' => 'label'];
33
34
    /** {@inheritdoc} */
35
    public $_primaryFilter = 'descr';
36
37
    /** {@inheritdoc} */
38 View Code Duplication
    public function getPluginOptions($options = [])
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
        return parent::getPluginOptions([
41
            'select2Options' => [
42
                'templateResult' => new JsExpression("function (data) {
43
                    if (data.loading) {
44
                        return data.text;
45
                    }
46
                    var client = '<b>' + data.client + ':&nbsp;'
47
                        color = data.sum < 0 ? 'text-danger' : 'text-success';
48
                        sum = ' <span class=\"' + color +'\">' + data.sum + '</span> '
49
                        currency = ' ' + data.currency.toUpperCase() + '</b><br>'
50
                        descr = (data.descr ? data.descr : data.label);
51
52
                    return client + sum + currency + (descr ? descr : '<span class=\"text-muted\">--</span>');
53
                }"),
54
                'escapeMarkup' => new JsExpression('function (markup) {
55
                    return markup; // Allows HTML
56
                }'),
57
            ],
58
        ]);
59
    }
60
61
    /** {@inheritdoc} */
62
    public function getFilter()
63
    {
64
        return ArrayHelper::merge(parent::getFilter(), [
65
            'ftype' => ['format' => 'other,hw_purchase'],
66
            'limit' => ['format' => '50'],
67
        ]);
68
    }
69
}
70