ActionColumn   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initDefaultButtons() 0 9 4
B initDefaultButton() 0 31 7
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\grid;
14
15
use Yii;
16
use yii\helpers\Html;
17
18
/**
19
 * Class ActionColumn
20
 * @package rhosocial\user\grid
21
 * @version 1.0
22
 * @author vistart <[email protected]>
23
 */
24
class ActionColumn extends \yii\grid\ActionColumn
25
{
26
    /**
27
     * @var bool Indicate whether the default buttons use icon or not.
28
     */
29
    public $useIcon = true;
30
31
    /**
32
     * Initializes the default button rendering callbacks.
33
     */
34
    protected function initDefaultButtons()
35
    {
36
        $this->initDefaultButton('view', $this->useIcon ? 'eye-open' : false);
0 ignored issues
show
Security Bug introduced by
It seems like $this->useIcon ? 'eye-open' : false can also be of type false; however, rhosocial\user\grid\Acti...mn::initDefaultButton() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
37
        $this->initDefaultButton('update', $this->useIcon ? 'pencil' : false);
0 ignored issues
show
Security Bug introduced by
It seems like $this->useIcon ? 'pencil' : false can also be of type false; however, rhosocial\user\grid\Acti...mn::initDefaultButton() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
38
        $this->initDefaultButton('delete', $this->useIcon ? 'trash' : false, [
0 ignored issues
show
Security Bug introduced by
It seems like $this->useIcon ? 'trash' : false can also be of type false; however, rhosocial\user\grid\Acti...mn::initDefaultButton() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
39
            'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
40
            'data-method' => 'post',
41
        ]);
42
    }
43
44
    /**
45
     * Initializes the default button rendering callback for single button
46
     * @param string $name Button name as it's written in template
47
     * @param string $iconName The part of Bootstrap glyphicon class that makes it unique
48
     * @param array $additionalOptions Array of additional options
49
     */
50
    protected function initDefaultButton($name, $iconName, $additionalOptions = [])
51
    {
52
        if (!isset($this->buttons[$name]) && strpos($this->template, '{' . $name . '}') !== false) {
53
            $this->buttons[$name] = function ($url, $model, $key) use ($name, $iconName, $additionalOptions) {
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...
54
                switch ($name) {
55
                    case 'view':
56
                        $title = Yii::t('yii', 'View');
57
                        break;
58
                    case 'update':
59
                        $title = Yii::t('yii', 'Update');
60
                        break;
61
                    case 'delete':
62
                        $title = Yii::t('yii', 'Delete');
63
                        break;
64
                    default:
65
                        $title = ucfirst($name);
66
                }
67
                $options = array_merge([
68
                    'title' => $title,
69
                    'aria-label' => $title,
70
                    'data-pjax' => '0',
71
                ], $additionalOptions, $this->buttonOptions);
72
                if ($iconName == false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $iconName of type string to the boolean false. If you are specifically checking for an empty string, consider using the more explicit === '' instead.
Loading history...
73
                    $icon = $options['title'];
74
                } else {
75
                    $icon = Html::tag('span', '', ['class' => "glyphicon glyphicon-$iconName"]);
76
                }
77
                return Html::a($icon, $url, $options);
78
            };
79
        }
80
    }
81
}
82