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

ActionColumn::initDefaultButtons()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 38
Code Lines 30

Duplication

Lines 22
Ratio 57.89 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 22
loc 38
rs 8.5806
c 0
b 0
f 0
ccs 0
cts 36
cp 0
cc 4
eloc 30
nc 8
nop 0
crap 20
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