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.

CleanRelations::cleanUpRelations()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 8.6097
c 0
b 0
f 0
cc 6
nc 7
nop 0
1
<?php
2
3
namespace app\behaviors;
4
5
use app\modules\image\models\Image;
6
use app\models\BaseObject;
7
use app\models\ObjectPropertyGroup;
8
use app\models\ObjectStaticValues;
9
use app\models\ViewObject;
10
use Yii;
11
use yii\base\Behavior;
12
use yii\db\ActiveRecord;
13
use yii\db\Exception;
14
15
/**
16
 * Class CleanRelations behavior.
17
 * @package app\behaviors
18
 */
19
class CleanRelations extends Behavior
20
{
21
    /**
22
     * Get events list.
23
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<*,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
24
     */
25
    public function events()
26
    {
27
        return [
28
            ActiveRecord::EVENT_BEFORE_DELETE => 'cleanUpRelations',
29
        ];
30
    }
31
32
    /**
33
     * Delete relations
34
     * @return bool
35
     */
36
    public function cleanUpRelations()
37
    {
38
        if (!is_subclass_of($this->owner, '\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...
39
            return false;
40
        }
41
        if (isset($this->owner->is_deleted) && (0 === intval($this->owner->is_deleted))) {
42
            return false;
43
        }
44
        if (null === $object = BaseObject::getForClass($this->owner->className())) {
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
            return false;
46
        }
47
        $whereDelete = [
48
            'object_id' => $object->id,
49
            'object_model_id' => $this->owner->id
50
        ];
51
        ObjectPropertyGroup::deleteAll($whereDelete);
52
        ObjectStaticValues::deleteAll($whereDelete);
53
        Image::deleteAll($whereDelete);
54
        ViewObject::deleteAll($whereDelete);
55
        try {
56
            Yii::$app->db->createCommand()->delete(
57
                $object->categories_table_name,
58
                [
59
                    'object_model_id' => $this->owner->id,
60
                ]
61
            )->execute();
62
            Yii::$app->db->createCommand()->delete(
63
                $object->column_properties_table_name,
64
                [
65
                    'object_model_id' => $this->owner->id,
66
                ]
67
            )->execute();
68
            Yii::$app->db->createCommand()->delete(
69
                $object->eav_table_name,
70
                [
71
                    'object_model_id' => $this->owner->id,
72
                ]
73
            )->execute();
74
        } catch (Exception $e) {
75
            // do nothing
76
        }
77
        return true;
78
    }
79
}
80