GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — filters ( 17a6ca...8fddb4 )
by
unknown
12:09
created

PublishSwitchButtons::renderButtons()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 3
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace app\backend\widgets;
4
5
use yii\base\InvalidParamException;
6
use yii\base\Widget;
7
use yii\helpers\Html;
8
use kartik\icons\Icon;
9
use Yii;
10
11
class PublishSwitchButtons extends Widget
12
{
13
    const MASS_PUBLISH = 'publish';
14
    const MASS_UNPUBLISH = 'unpublish';
15
16
    public $url;
17
    public $gridSelector;
18
    public $wrapperClass = '';
19
    public $publishText = '';
20
    public $unpublishText = '';
21
    /**
22
     * @var array here you can define buttons classes like this:
23
     * [
24
     *  'on-class' => 'btn btn-danger', //class for publish all button
25
     *  'off-class' => 'btn btn-danger', //class for unpublish all button
26
     * ]
27
     *
28
     */
29
    public $htmlOptions = [];
30
    public $modalSelector = '#mass-publish-confirmation';
31
32
    public function init()
33
    {
34
        if (!isset($this->url, $this->gridSelector)) {
35
            throw new InvalidParamException('Attribute \'url\' or \'gridSelector\' is not set');
36
        }
37
        if (true === empty($this->publishText)) {
38
            $this->publishText = Yii::t('app', 'Are you sure you want to publish all selected items?');
39
        }
40
        if (true === empty($this->unpublishText)) {
41
            $this->unpublishText = Yii::t('app', 'Are you sure you want to unpublish all selected items?');
42
        }
43
        if (!isset($this->htmlOptions['id'])) {
44
            $this->htmlOptions['id'] = 'publishSwitch';
45
        }
46
    }
47
48
    public function run()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        $this->registerScript();
51
        return $this->renderButtons();
52
    }
53
54
    protected function renderButtons()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
55
    {
56
        $buttons = Html::button(
57
                Icon::show('eye') . ' ' .
58
                \Yii::t('app', 'Publish All'),
59
                [
60
                    'class' => isset($this->htmlOptions['on-class']) ?
61
                        $this->htmlOptions['on-class'] : 'btn btn-default',
62
                    'data-action' => self::MASS_PUBLISH
63
                ]
64
65
            )
66
            . Html::button(
67
                Icon::show('eye-slash') . ' ' .
68
                \Yii::t('app', 'Unpublish All'),
69
                [
70
                    'class' => isset($this->htmlOptions['on-class'])
71
                        ? $this->htmlOptions['on-class'] : 'btn btn-default',
72
                    'data-action' => self::MASS_UNPUBLISH
73
                ]
74
            );
75
        return Html::tag('div', $buttons, [
76
            'id' => $this->htmlOptions['id'],
77
            'class' => 'btn-group ' . $this->wrapperClass,
78
            'role' => 'group',
79
        ]);
80
    }
81
82
    protected function registerScript()
83
    {
84
        $JS = <<<JS
85
            $("#{$this->htmlOptions['id']} button").on('click', function() {
86
                var items =  $("{$this->gridSelector}").yiiGridView('getSelectedRows');
87
                if (items.length) {
88
                    var \$modal = $("{$this->modalSelector}"),
89
                        action = $(this).data('action'),
90
                        \$textContainer = $('#mass-publish-modal-text', \$modal);
91
                        \$textContainer.closest('.alert').removeClass('alert-danger').addClass('alert-info');
92
                    switch (action) {
93
                        case '%s' :
94
                            \$textContainer.text('{$this->publishText}');
95
                            break;
96
                        case '%s' :
97
                            \$textContainer.text('{$this->unpublishText}');
98
                            break;
99
                    }
100
                    \$modal.data('url', "{$this->url}")
101
                    .data('items', items)
102
                    .data('switch-action', action)
103
                    .modal('show');
104
                }
105
                return false;
106
            });
107
JS;
108
        $this->view->registerJs(sprintf($JS, self::MASS_PUBLISH, self::MASS_UNPUBLISH));
109
    }
110
}
111