Completed
Push — master ( 8fde5c...a8ecfd )
by Andrii
13:38
created

BackupGridView::columns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 73
Code Lines 51

Duplication

Lines 4
Ratio 5.48 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 73
ccs 0
cts 68
cp 0
rs 9.0675
c 0
b 0
f 0
cc 1
eloc 51
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\widgets\obj\ObjLinkWidget;
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
                'class' => MainColumn::class,
27
                'format' => 'html',
28
                'filterOptions' => ['class' => 'narrow-filter'],
29
            ],
30
            'object_id' => [
31
                'filterOptions' => ['class' => 'narrow-filter'],
32
            ],
33
            'backup' => [
34
                'class' => MainColumn::class,
35
                'filterAttribute' => 'backup_like',
36
            ],
37
            'server' => [
38
                'class' => ServerColumn::class,
39
            ],
40
            'account' => [
41
                'class' => AccountColumn::class,
42
            ],
43
            'object' => [
44
                'format' => 'raw',
45
                'attribute' => 'name',
46
                'filterAttribute' => 'name_like',
47
                'filterOptions' => ['class' => 'narrow-filter'],
48 View Code Duplication
                'value' => function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
                    return  Html::a($model->name, ['@backuping/view', 'id' => $model->object_id], ['class' => 'bold']) . ' ' .
50
                            ObjLinkWidget::widget(['model' => $model->getObj()]);
51
                },
52
            ],
53
            'name' => [
54
                'format' => 'raw',
55
                'attribute' => 'name',
56
                'value' => function ($model) {
57
                    return ObjLinkWidget::widget(['label' => $model->name, 'model' => $model->getObj()]);
58
                },
59
            ],
60
            'size' => [
61
                'filter' => false,
62
                'value' => function ($model) {
63
                    return Yii::$app->formatter->asShortSize($model->size, 2);
64
                },
65
            ],
66
            'time' => [
67
                'filter' => false,
68
                'value' => function ($model) {
69
                    return Yii::$app->formatter->asDatetime($model->time);
70
                },
71
            ],
72
            'actions' => [
73
                'class' => ActionColumn::class,
74
                'template' => '{view} {delete}',
75
            ],
76
            'inner_actions' => [
77
                'class' => ActionColumn::class,
78
                'template' => '{deleteBackup}',
79
                'buttons' => [
80
                    '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...
81
                        return Html::a('<i class="fa fa-trash-o"></i>&nbsp;' . Yii::t('hipanel', 'Delete'), ['/hosting/backup/delete', 'id' => $model->id], [
82
                            'aria-label'   => Yii::t('hipanel', 'Delete'),
83
                            'class' => 'btn btn-danger btn-xs',
84
                            'data' => [
85
                                'confirm' => Yii::t('hipanel', 'Are you sure you want to delete this item?'),
86
                                'method'  => 'POST',
87
                                'data-pjax' => '0',
88
                            ],
89
                        ]);
90
                    },
91
                ],
92
            ],
93
        ]);
94
    }
95
}
96