Passed
Push — develop ( ba218d...929d5c )
by
unknown
01:43
created

ActionColumn   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 51.16 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 22
loc 43
rs 10
c 0
b 0
f 0
ccs 0
cts 36
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B initDefaultButtons() 22 38 4

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
namespace app\modules\grid;
4
5
use Yii;
6
use yii\grid\ActionColumn as YiiActionColumn;
7
use yii\helpers\Html;
8
9
class ActionColumn extends YiiActionColumn
10
{
11
    public $headerOptions = ['width' => '110', 'class' => 'action-column'];
12
13
    protected function initDefaultButtons()
14
    {
15 View Code Duplication
        if (!isset($this->buttons['view'])) {
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...
16
            $this->buttons['view'] = function ($url, $model, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $model 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...
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...
17
                $options = array_merge([
18
                    'title' => Yii::t('yii', 'View'),
19
                    'aria-label' => Yii::t('yii', 'View'),
20
                    'data-pjax' => '0',
21
                    'class' => 'btn btn-primary',
22
                ], $this->buttonOptions);
23
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
24
            };
25
        }
26 View Code Duplication
        if (!isset($this->buttons['update'])) {
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...
27
            $this->buttons['update'] = function ($url, $model, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $model 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...
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...
28
                $options = array_merge([
29
                    'title' => Yii::t('yii', 'Update'),
30
                    'aria-label' => Yii::t('yii', 'Update'),
31
                    'data-pjax' => '0',
32
                    'class' => 'btn btn-info',
33
                ], $this->buttonOptions);
34
                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
35
            };
36
        }
37
        if (!isset($this->buttons['delete'])) {
38
            $this->buttons['delete'] = function ($url, $model, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $model 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...
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...
39
                $options = array_merge([
40
                    'title' => Yii::t('yii', 'Delete'),
41
                    'aria-label' => Yii::t('yii', 'Delete'),
42
                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
43
                    'data-method' => 'post',
44
                    'data-pjax' => '0',
45
                    'class' => 'btn btn-danger',
46
                ], $this->buttonOptions);
47
                return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);
48
            };
49
        }
50
    }
51
}
52