Completed
Push — master ( 79eefd...fb0012 )
by Klochok
13:04
created

HubGridView::defaultColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 51
rs 9.4109
cc 1
eloc 36
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 static function defaultColumns()
15
    {
16
        return [
17
            'actions' => [
18
                'class' => MenuColumn::class,
19
                'menuClass' => HubActionsMenu::class,
20
            ],
21
            'traf_server_id' => [
22
                'format' => 'html',
23
                'value' => function ($model) {
24
                    return Html::a($model->traf_server_id_label, ['@server/view', 'id' => $model->traf_server_id]);
25
                }
26
            ],
27
            'vlan_server_id' => [
28
                'format' => 'html',
29
                'value' => function ($model) {
30
                    return Html::a($model->vlan_server_id_label, ['@server/view', 'id' => $model->vlan_server_id]);
31
                }
32
            ],
33
            'buyer' => [
34
                'class' => ClientColumn::class,
35
                'idAttribute' => 'buyer_id',
36
                'attribute' => 'buyer_id',
37
                'nameAttribute' => 'buyer',
38
                'enableSorting' => false,
39
40
            ],
41
            'switch' => [
42
                'format' => 'html',
43
                'label' => Yii::t('hipanel:server', 'Switch'),
44
                'value' => function ($model) {
45
                    $name = Html::tag('span', $model->name, ['class' => 'text-bold text-info']);
46
                    $note = Html::tag('small', $model->note, ['class' => 'text-muted']);
47
                    return sprintf('%s %s %s', $name, '', $note);
48
                }
49
            ],
50
            'type' => [
51
                'class' => RefColumn::class,
52
                'findOptions' => [
53
                    'select' => 'full',
54
                    'mapOptions' => ['from' => 'id', 'to' => 'label'],
55
                ],
56
                'attribute' => 'type_id',
57
                'i18nDictionary' => 'hipanel:server:hub',
58
                'gtype' => 'type,device,switch',
59
                'value' => function ($model) {
60
                    return Yii::t('hipanel:server:hub', $model->type_label);
61
                },
62
            ],
63
        ];
64
    }
65
}
66