Completed
Push — master ( 055fd1...11841d )
by Klochok
24:15 queued 09:17
created

DbGridView::columns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 59
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 59
ccs 0
cts 57
cp 0
rs 9.597
cc 1
eloc 42
nc 1
nop 0
crap 2

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
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\grid;
12
13
use hipanel\grid\ActionColumn;
14
use hipanel\grid\BoxedGridView;
15
use hipanel\grid\MainColumn;
16
use hipanel\grid\RefColumn;
17
use hipanel\grid\XEditableColumn;
18
use hipanel\modules\hosting\widgets\backup\BackupGridRow;
19
use hipanel\modules\hosting\widgets\db\State;
20
use hipanel\modules\server\grid\ServerColumn;
21
use Yii;
22
23
class DbGridView extends BoxedGridView
24
{
25
    public function columns()
26
    {
27
        return array_merge(parent::columns(), [
28
            'name'          => [
29
                'class'           => MainColumn::class,
30
                'format' => 'html',
31
                'attribute'       => 'name',
32
                'filterAttribute' => 'name_like',
33
            ],
34
            'state'       => [
35
                'class'  => RefColumn::class,
36
                'i18nDictionary' => 'hipanel:hosting',
37
                'format' => 'raw',
38
                'value'  => function ($model) {
39
                    return State::widget(compact('model'));
40
                },
41
                'gtype'  => 'state,db',
42
            ],
43
            'account' => [
44
                'class' => AccountColumn::class,
45
            ],
46
            'server'      => [
47
                'class' => ServerColumn::class,
48
            ],
49
            'service_ip'  => [
50
                'filter' => false,
51
            ],
52
            'description' => [
53
                'class' => XEditableColumn::class,
54
                'pluginOptions' => [
55
                    'url' => 'set-description',
56
                ],
57
                'filter'  => true,
58
                'popover' => Yii::t('hipanel', 'Make any notes for your convenience'),
59
            ],
60
            'password' => [
61
                'class' => XEditableColumn::class,
62
                'pluginOptions' => [
63
                    'url' => 'set-password',
64
                ],
65
                'filter'  => true,
66
                'popover' => Yii::t('hipanel', 'Change password'),
67
                'value'   => function () {
68
                    return Yii::t('hipanel', 'Change password');
69
                },
70
            ],
71
            'backups_widget' => [
72
                'label' => Yii::t('hipanel:hosting', 'Backups'),
73
                'format' => 'raw',
74
                'value' => function ($model) {
75
                    return BackupGridRow::widget(['model' => $model]);
76
                },
77
            ],
78
            'actions'     => [
79
                'class'    => ActionColumn::class,
80
                'template' => '{view} {delete}',
81
            ],
82
        ]);
83
    }
84
}
85