Completed
Push — master ( 82e6a4...a94b7d )
by Klochok
11:17
created

HubGridView::defaultColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
c 7
b 0
f 0
dl 0
loc 68
rs 9.2447
cc 1
eloc 49
nc 1
nop 0

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
namespace hipanel\modules\server\grid;
4
5
use hipanel\grid\RefColumn;
6
use hipanel\modules\client\grid\ClientColumn;
7
use hipanel\modules\server\menus\HubActionsMenu;
8
use hiqdev\yii2\menus\grid\MenuColumn;
9
use Yii;
10
use yii\helpers\Html;
11
12
class HubGridView extends \hipanel\grid\BoxedGridView
13
{
14
    public function columns()
15
    {
16
        return array_merge(parent::columns(), [
0 ignored issues
show
Bug introduced by
The method columns() does not exist on hipanel\grid\BoxedGridView. Did you maybe mean column()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
17
            'inn' => [
18
                'enableSorting' => false,
19
            ],
20
            'model' => [
21
                'enableSorting' => false,
22
            ],
23
            'ip' => [
24
                'enableSorting' => false,
25
            ],
26
            'mac' => [
27
                'enableSorting' => false,
28
            ],
29
            'actions' => [
30
                'class' => MenuColumn::class,
31
                'menuClass' => HubActionsMenu::class,
32
            ],
33
            'traf_server_id' => [
34
                'format' => 'html',
35
                'enableSorting' => false,
36
                'value' => function ($model) {
37
                    return Html::a($model->traf_server_id_label, ['@server/view', 'id' => $model->traf_server_id]);
38
                }
39
            ],
40
            'vlan_server_id' => [
41
                'format' => 'html',
42
                'enableSorting' => false,
43
                'value' => function ($model) {
44
                    return Html::a($model->vlan_server_id_label, ['@server/view', 'id' => $model->vlan_server_id]);
45
                }
46
            ],
47
            'buyer' => [
48
                'label' => Yii::t('hipanel:server:hub', 'Buyer'),
49
                'class' => ClientColumn::class,
50
                'idAttribute' => 'buyer_id',
51
                'attribute' => 'buyer_id',
52
                'nameAttribute' => 'buyer',
53
                'enableSorting' => false,
54
55
            ],
56
            'switch' => [
57
                'format' => 'html',
58
                'enableSorting' => false,
59
                'label' => Yii::t('hipanel:server', 'Switch'),
60
                'value' => function ($model) {
61
                    $name = Html::tag('span', $model->name, ['class' => 'text-bold text-info']);
62
                    $note = Html::tag('small', $model->note, ['class' => 'text-muted']);
63
                    return sprintf('%s %s %s', $name, '', $note);
64
                }
65
            ],
66
            'type' => [
67
                'class' => RefColumn::class,
68
                'enableSorting' => false,
69
                'findOptions' => [
70
                    'select' => 'full',
71
                    'mapOptions' => ['from' => 'id', 'to' => 'label'],
72
                ],
73
                'attribute' => 'type_id',
74
                'i18nDictionary' => 'hipanel:server:hub',
75
                'gtype' => 'type,device,switch',
76
                'value' => function ($model) {
77
                    return Yii::t('hipanel:server:hub', $model->type_label);
78
                },
79
            ],
80
        ]);
81
    }
82
}
83