PurseGridView::columns()   B
last analyzed

Complexity

Conditions 5
Paths 1

Size

Total Lines 114

Duplication

Lines 62
Ratio 54.39 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 62
loc 114
ccs 0
cts 102
cp 0
rs 7.6888
c 0
b 0
f 0
cc 5
nc 1
nop 0
crap 30

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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