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

BackupGridView   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 76
Duplicated Lines 5.26 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 4
loc 76
ccs 0
cts 69
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A columns() 4 73 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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