Completed
Push — master ( 1bd5c4...f57b87 )
by Dmitry
23:17 queued 08:17
created

HubGridView::columns()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 78
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 60
dl 0
loc 78
ccs 0
cts 64
cp 0
rs 8.8727
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 6

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
 * Server module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\grid;
12
13
use hipanel\grid\MainColumn;
14
use hipanel\grid\RefColumn;
15
use hipanel\modules\client\grid\ClientColumn;
16
use hipanel\modules\server\menus\HubActionsMenu;
17
use hipanel\modules\server\models\Hub;
18
use hipanel\widgets\gridLegend\ColorizeGrid;
19
use hiqdev\yii2\menus\grid\MenuColumn;
20
use Yii;
21
use yii\helpers\Html;
22
23
class HubGridView extends \hipanel\grid\BoxedGridView
24
{
25
    use ColorizeGrid;
0 ignored issues
show
introduced by
The trait hipanel\widgets\gridLegend\ColorizeGrid requires some properties which are not provided by hipanel\modules\server\grid\HubGridView: $controller, $module
Loading history...
26
27
    public function columns()
28
    {
29
        return array_merge(parent::columns(), [
30
            'inn' => [
31
                'enableSorting' => false,
32
                'filterOptions' => ['class' => 'narrow-filter'],
33
            ],
34
            'model' => [
35
                'enableSorting' => false,
36
                'filterOptions' => ['class' => 'narrow-filter'],
37
            ],
38
            'ip' => [
39
                'enableSorting' => false,
40
                'filterOptions' => ['class' => 'narrow-filter'],
41
            ],
42
            'mac' => [
43
                'enableSorting' => false,
44
                'filterOptions' => ['class' => 'narrow-filter'],
45
            ],
46
            'actions' => [
47
                'class' => MenuColumn::class,
48
                'menuClass' => HubActionsMenu::class,
49
            ],
50
            'traf_server_id' => [
51
                'format' => 'html',
52
                'enableSorting' => false,
53
                'value' => function ($model) {
54
                    return Html::a($model->traf_server_id_label, ['@server/view', 'id' => $model->traf_server_id]);
55
                },
56
            ],
57
            'vlan_server_id' => [
58
                'format' => 'html',
59
                'enableSorting' => false,
60
                'value' => function ($model) {
61
                    return Html::a($model->vlan_server_id_label, ['@server/view', 'id' => $model->vlan_server_id]);
62
                },
63
            ],
64
            'buyer' => [
65
                'label' => Yii::t('hipanel:server:hub', 'Buyer'),
66
                'class' => ClientColumn::class,
67
                'idAttribute' => 'buyer_id',
68
                'attribute' => 'buyer_id',
69
                'nameAttribute' => 'buyer',
70
                'enableSorting' => false,
71
            ],
72
            'switch' => [
73
                'class' => MainColumn::class,
74
                'attribute' => 'name',
75
                'filterAttribute' => 'name_ilike',
76
                'note' => 'note',
77
            ],
78
            'type' => [
79
                'class' => RefColumn::class,
80
                'filterOptions' => ['class' => 'narrow-filter'],
81
                'enableSorting' => false,
82
                'findOptions' => [
83
                    'select' => 'full',
84
                    'mapOptions' => ['from' => 'id', 'to' => 'label'],
85
                ],
86
                'attribute' => 'type_id',
87
                'i18nDictionary' => 'hipanel:server:hub',
88
                'gtype' => 'type,device,switch',
89
                'value' => function ($model) {
90
                    return Yii::t('hipanel:server:hub', $model->type_label);
91
                },
92
            ],
93
            'tariff' => [
94
                'format' => 'raw',
95
                'filterAttribute' => 'tariff_like',
96
                'value' => function (Hub $model): string {
97
                    return Yii::$app->user->can('plan.read')
0 ignored issues
show
Bug introduced by
The method can() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

97
                    return Yii::$app->user->/** @scrutinizer ignore-call */ can('plan.read')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The expression return Yii::app->user->c...f_id)) : $model->tariff could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
98
                        ? Html::a($model->tariff, ['@plan/view', 'id' => $model->tariff_id])
0 ignored issues
show
Bug Best Practice introduced by
The property tariff does not exist on hipanel\modules\server\models\Hub. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property tariff_id does not exist on hipanel\modules\server\models\Hub. Since you implemented __get, consider adding a @property annotation.
Loading history...
99
                        : $model->tariff;
100
                },
101
            ],
102
            'sale_time' => [
103
                'attribute' => 'sale_time',
104
                'format' => 'datetime',
105
            ],
106
        ]);
107
    }
108
}
109