PurseGridView   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 117
Duplicated Lines 52.99 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 62
loc 117
ccs 0
cts 103
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B columns() 62 114 5

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\grid;
12
13
use hipanel\modules\client\widgets\combo\ContactCombo;
14
use hipanel\modules\finance\widgets\combo\RequisitesCombo;
15
use hiqdev\xeditable\widgets\ComboXEditable;
16
use Yii;
17
18
class PurseGridView extends \hipanel\grid\BoxedGridView
19
{
20
    public function columns()
21
    {
22
        return array_merge(parent::columns(), [
23
            'balance' => [
24
                'class' => 'hipanel\modules\finance\grid\BalanceColumn',
25
            ],
26
            'credit' => CreditColumn::resolveConfig(),
27
            'invoices' => [
28
                'class' => MonthlyDocumentsColumn::class,
29
                'type' => 'invoice',
30
            ],
31
            'serviceInvoices' => [
32
                'class' => MonthlyDocumentsColumn::class,
33
                'type' => 'service_invoice',
34
            ],
35
            'purchaseInvoices' => [
36
                'class' => MonthlyDocumentsColumn::class,
37
                'type' => 'purchase_invoice',
38
            ],
39
            'acceptances' => [
40
                'class' => MonthlyDocumentsColumn::class,
41
                'type' => 'acceptance',
42
            ],
43
            'internalinvoices' => [
44
                'class' => MonthlyDocumentsColumn::class,
45
                'type' => 'internal_invoice',
46
                'label' => Yii::t('hipanel:finance', 'Internal invoice'),
47
            ],
48
            'contracts' => [
49
                'class' => DocumentsColumn::class,
50
                'type' => 'contract',
51
            ],
52
            'probations' => [
53
                'class' => DocumentsColumn::class,
54
                'type' => 'probation',
55
            ],
56
            'ndas' => [
57
                'class' => DocumentsColumn::class,
58
                'type' => 'nda',
59
            ],
60
            'taxes' => [
61
            ],
62
            'contact' => [
63
                'format' => 'raw',
64
                'label' => Yii::t('hipanel:finance', 'Contact'),
65 View Code Duplication
                'value' => function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
66
                    $organization = $model->contact->organization;
67
                    $result = $organization . ($organization ? ' / ' : '') . $model->contact->name;
68
69
                    if (!Yii::$app->user->can('purse.update')) {
70
                        return $result;
71
                    }
72
73
                    return ComboXEditable::widget([
74
                        'model' => $model,
75
                        'attribute' => 'contact_id',
76
                        'value' => $result,
77
                        'pluginOptions' => [
78
                            'url' => ['@purse/update-contact', 'id' => $model->id],
79
                        ],
80
                        'combo' => [
81
                            'class' => ContactCombo::class,
82
                            'filter' => [
83
                                'client_id' => ['format' => $model->id],
84
                            ],
85
                            'current' => [
86
                                $model->contact_id => $result,
87
                            ],
88
                            'pluginOptions' => [
89
                                'select2Options' => [
90
                                    'width' => '40rem',
91
                                ],
92
                            ],
93
                        ],
94
                    ]);
95
                },
96
            ],
97
            'requisite' => [
98
                'format' => 'raw',
99
                'label' => Yii::t('hipanel:finance', 'Payment details'),
100 View Code Duplication
                'value' => function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
101
                    $organization = $model->requisite->organization;
102
                    $result = $organization . ($organization ? ' / ' : '') . $model->requisite->name;
103
104
                    if (!Yii::$app->user->can('purse.update')) {
105
                        return $result;
106
                    }
107
108
                    return ComboXEditable::widget([
109
                        'model' => $model,
110
                        'attribute' => 'requisite_id',
111
                        'value' => $result,
112
                        'pluginOptions' => [
113
                            'url' => ['@purse/update-requisite', 'id' => $model->id],
114
                        ],
115
                        'combo' => [
116
                            'class' => RequisitesCombo::class,
117
                            'filter' => [
118
                                'client_id' => ['format' => $model->seller_id],
119
                            ],
120
                            'current' => [
121
                                $model->requisite_id => $result,
122
                            ],
123
                            'pluginOptions' => [
124
                                'select2Options' => [
125
                                    'width' => '40rem',
126
                                ],
127
                            ],
128
                        ],
129
                    ]);
130
                },
131
            ],
132
        ]);
133
    }
134
}
135