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

BackupGridView::columns()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 77
Code Lines 54

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 77
ccs 0
cts 72
cp 0
rs 8.9342
cc 1
eloc 54
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\MainColumn;
15
use hipanel\modules\hosting\widgets\backup\ObjectLabelWidget;
16
use hipanel\modules\server\grid\ServerColumn;
17
use Yii;
18
use yii\helpers\Html;
19
20
class BackupGridView extends \hipanel\grid\BoxedGridView
21
{
22
    public function columns()
23
    {
24
        return array_merge(parent::columns(), [
25
            'id' => [
26
                'format' => 'html',
27
                'attribute' => 'id',
28
                'value' => function ($model) {
29
                    return Html::tag('span', $model->id, ['class' => 'bold']);
30
                },
31
            ],
32
            'object_id' => [
33
                'class' => MainColumn::class,
34
                'filterAttribute' => 'id',
35
                'attribute' => 'object_id',
36
            ],
37
            'backup' => [
38
                'class' => MainColumn::class,
39
                'filterAttribute' => 'backup_like',
40
            ],
41
            'server' => [
42
                'class' => ServerColumn::class,
43
            ],
44
            'account' => [
45
                'class' => AccountColumn::class,
46
            ],
47
            'object' => [
48
                'format' => 'raw',
49
                'attribute' => 'name',
50
                'filterAttribute' => 'name_like',
51
                'value' => function ($model) {
52
                    $labelType = ObjectLabelWidget::widget(compact('model'));
53
                    return $labelType . '&nbsp;' .
54
                        Html::a($model->name, ["@{$model->object}/view", 'id' => $model->object_id], ['data-pjax' => 0]);
55
                },
56
            ],
57
            'name' => [
58
                'format' => 'raw',
59
                'attribute' => 'name',
60
                'value' => function ($model) {
61
                    return Html::a($model->name, ["@{$model->object}/view", 'id' => $model->object_id], ['data-pjax' => 0]);
62
                },
63
            ],
64
            'size' => [
65
                'filter' => false,
66
                'value' => function ($model) {
67
                    return Yii::$app->formatter->asShortSize($model->size, 2);
68
                },
69
            ],
70
            'time' => [
71
                'filter' => false,
72
                'value' => function ($model) {
73
                    return Yii::$app->formatter->asDatetime($model->time);
74
                },
75
            ],
76
            'actions' => [
77
                'class' => ActionColumn::class,
78
                'template' => '{view} {delete}',
79
            ],
80
            'inner_actions' => [
81
                'class' => ActionColumn::class,
82
                'template' => '{deleteBackup}',
83
                'buttons' => [
84
                    'deleteBackup' => function ($url, $model, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
                        return Html::a('<i class="fa fa-trash-o"></i>&nbsp;' . Yii::t('hipanel', 'Delete'), ['/hosting/backup/delete', 'id' => $model->id], [
86
                            'aria-label'   => Yii::t('hipanel', 'Delete'),
87
                            'class' => 'btn btn-danger btn-xs',
88
                            'data' => [
89
                                'confirm' => Yii::t('hipanel', 'Are you sure you want to delete this item?'),
90
                                'method'  => 'POST',
91
                                'data-pjax' => '0',
92
                            ],
93
                        ]);
94
                    },
95
                ],
96
            ],
97
        ]);
98
    }
99
}
100