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 ( 69e989...d867fc )
by
unknown
11:24
created

CategoryMovementsAction   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 18 4
A run() 0 18 4
A move() 0 5 1
B add() 0 24 3
1
<?php
2
3
namespace app\backend\actions;
4
5
6
use app\models\Object;
7
use app\modules\shop\models\Category;
8
use app\modules\shop\models\Product;
9
use devgroup\TagDependencyHelper\ActiveRecordHelper;
10
use yii\base\Action;
11
use Yii;
12
use yii\caching\TagDependency;
13
use yii\db\Query;
14
use yii\web\NotFoundHttpException;
15
use yii\web\ServerErrorHttpException;
16
use app\backend\widgets\CategoryMovementsButtons;
17
18
class CategoryMovementsAction extends Action
19
{
20
    private $categoryId;
21
    private $items = [];
22
    private $action;
23
    /** @var  Object */
24
    private static $object;
25
26
    /**
27
     * @throws NotFoundHttpException
28
     * @throws ServerErrorHttpException
29
     */
30
    public function init()
31
    {
32
        if (false === Yii::$app->request->isAjax) {
33
            throw new NotFoundHttpException('Page not found');
34
        }
35
        $catId = Yii::$app->request->post('cat-id');
36
        if (null !== Category::findOne(['id' => $catId])) {
37
            $this->categoryId = $catId;
38
        } else {
39
            throw new ServerErrorHttpException("Can't find Category with id {$catId}");
40
        }
41
        if (true === empty(static::$object)) {
1 ignored issue
show
Bug introduced by
Since $object is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $object to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
42
            static::$object = Object::getForClass(Product::className());
1 ignored issue
show
Bug introduced by
Since $object is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $object to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
43
        }
44
        $this->action = Yii::$app->request->post('action', '');
45
        $this->items = Yii::$app->request->post('mc-items', []);
46
        parent::init();
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function run()
53
    {
54
        $n = 0;
55
        switch($this->action) {
56
            case CategoryMovementsButtons::ADD_ACTION :
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...
57
                $n = $this->add();
58
                break;
59
            case CategoryMovementsButtons::MOVE_ACTION :
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...
60
                $n = $this->move();
61
                break;
62
        }
63
        $tags = [];
64
        foreach ($this->items as $id) {
65
            $tags[] = ActiveRecordHelper::getObjectTag(Product::className(), $id);
66
        }
67
        TagDependency::invalidate(Yii::$app->cache, $tags);
68
        Yii::$app->session->setFlash('info', Yii::t('app', 'Items updated: {n}', ['n' => $n]));
69
    }
70
71
    /**
72
     * @return int
73
     */
74
    private function move()
75
    {
76
        $this->add();
77
        return Product::updateAll(['main_category_id' => $this->categoryId],['id' => $this->items]);
78
    }
79
80
    /**
81
     * @return int
82
     * @throws \yii\db\Exception
83
     */
84
    private function add()
85
    {
86
        $exists = (new Query())->select('object_model_id')
87
            ->from(static::$object->categories_table_name)
1 ignored issue
show
Bug introduced by
Since $object is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $object to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
88
            ->where([
89
                'category_id' => $this->categoryId,
90
                'object_model_id' => $this->items
91
            ])
92
            ->column();
93
        $new = array_diff($this->items, $exists);
94
        $rows = [];
95
        foreach ($new as $id) {
96
            $rows[] = [$this->categoryId, $id, 0];
97
        }
98
        $n = 0;
99
        if (false === empty($rows)) {
100
            $n = Yii::$app->db->createCommand()->batchInsert(
101
                static::$object->categories_table_name,
1 ignored issue
show
Bug introduced by
Since $object is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $object to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
102
                ['category_id', 'object_model_id', 'sort_order'],
103
                $rows
104
            )->execute();
105
        }
106
        return $n;
107
    }
108
}