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

MassPublishAction   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 3
C run() 0 28 7
1
<?php
2
/**
3
 * this Action provides group publish and unpublish functionality.
4
 * Usage example: in backend controller
5
 * public function actions()
6
 * {
7
 *  return [
8
 *  ...
9
 *      'publish-switch' => [
10
 *          'class' => app\backend\actions\MassPublishAction::className(),
11
 *          'modelName' => Page::className(),
12
 *          'attribute' => 'published',
13
 *      ]
14
 * ];
15
 * @property string $modelName must be name of existing Model class. This property is required
16
 * @property string $attribute name of model attribute that provides public item visibility
17
 */
18
19
namespace app\backend\actions;
20
21
use Yii;
22
use yii\base\Action;
23
use yii\web\Response;
24
use yii\web\NotFoundHttpException;
25
use app\backend\widgets\PublishSwitchButtons;
26
use yii\web\ServerErrorHttpException;
27
28
class MassPublishAction extends Action
29
{
30
    public $modelName = '';
31
    public $attribute = '';
32
33
    /**
34
     * @throws ServerErrorHttpException
35
     */
36
    public function init()
37
    {
38
        parent::init();
39
        if (false === is_subclass_of($this->modelName, '\yii\db\ActiveRecord')) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
40
            throw new ServerErrorHttpException('Model class does not exists');
41
        }
42
        if (false === in_array($this->attribute, (new $this->modelName)->attributes())) {
43
            throw new ServerErrorHttpException("Model '{$this->modelName}' has no '{$this->attribute}' field'" );
44
        }
45
    }
46
47
    /**
48
     * @return int
49
     * @throws NotFoundHttpException
50
     */
51
    public function run()
52
    {
53
        if (false === Yii::$app->request->isAjax) {
54
            throw new NotFoundHttpException();
55
        }
56
        Yii::$app->response->format = Response::FORMAT_JSON;
57
        $items = is_array(Yii::$app->request->post('ps-items')) ? Yii::$app->request->post('ps-items') : [];
58
        $mode = Yii::$app->request->post('ps-action');
59
        $active = null;
60
        $message = '';
61
        switch ($mode) {
62
            case PublishSwitchButtons::MASS_PUBLISH :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
63
                $message = 'Items published: {n}';
64
                $active = 1;
65
                break;
66
            case PublishSwitchButtons::MASS_UNPUBLISH :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
67
                $message = 'Items unpublished: {n}';
68
                $active = 0;
69
                break;
70
        }
71
        if (false === empty($items) && null !== $active) {
72
            $class = $this->modelName;
73
            $num = $class::updateAll([$this->attribute => $active],['id' => $items]);
74
            Yii::$app->session->setFlash('info', Yii::t('app', $message, ['n' => $num]));
75
            return 1;
76
        }
77
        return 0;
78
    }
79
}