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.

PropertiesWidget   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 58 3
1
<?php
2
3
namespace app\properties;
4
5
use app\models\BaseObject;
6
use app\models\ObjectPropertyGroup;
7
use app\models\Property;
8
use app\models\PropertyGroup;
9
use app\models\PropertyStaticValues;
10
use devgroup\TagDependencyHelper\ActiveRecordHelper;
11
use Yii;
12
use yii\base\Widget;
13
use yii\caching\TagDependency;
14
use yii\db\ActiveRecord;
15
use yii\db\Query;
16
use yii\helpers\ArrayHelper;
17
use yii\widgets\ActiveForm;
18
19
/**
20
 * Class PropertiesWidget
21
 * @property ActiveRecord $model
22
 * @property ActiveForm $form
23
 * @property BaseObject $object
24
 * @property array $objectPropertyGroups
25
 * @property array $propertyGroupsToAdd
26
 * @property string $viewFile
27
 * @package app\properties
28
 */
29
class PropertiesWidget extends Widget
30
{
31
    private $object;
32
    private $objectPropertyGroups = [];
33
    private $propertyGroupsToAdd = [];
34
    public $form;
35
    public $model;
36
    public $viewFile = 'properties-widget';
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function run()
42
    {
43
        $this->object = BaseObject::getForClass(get_class($this->model));
44
        $cacheKey = 'PropertiesWidget: ' . get_class($this->model) . ':' . $this->model->id;
45
        $data = Yii::$app->cache->get($cacheKey);
46
        if ($data === false) {
47
            $this->objectPropertyGroups = ObjectPropertyGroup::getForModel($this->model);
48
            $addedPropertyGroupsIds = [];
49
            foreach ($this->objectPropertyGroups as $opg) {
50
                $addedPropertyGroupsIds[] = $opg->property_group_id;
51
            }
52
            $restPg = (new Query())
53
                ->select('id, name')
54
                ->from(PropertyGroup::tableName())
55
                ->where(
56
                    [
57
                        'object_id' => $this->object->id,
58
                    ]
59
                )->andWhere(
60
                    [
61
                        'not in', 'id', $addedPropertyGroupsIds,
62
                    ]
63
                )->orderBy('sort_order')
64
                ->all();
65
            $this->propertyGroupsToAdd = ArrayHelper::map($restPg, 'id', 'name');
66
            Yii::$app->cache->set(
67
                $cacheKey,
68
                [
69
                    'objectPropertyGroups' => $this->objectPropertyGroups,
70
                    'propertyGroupsToAdd' => $this->propertyGroupsToAdd,
71
                ],
72
                86400,
73
                new TagDependency(
74
                    [
75
                        'tags' => [
76
                            ActiveRecordHelper::getCommonTag(get_class($this->model)),
77
                            ActiveRecordHelper::getCommonTag(PropertyGroup::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...
78
                            ActiveRecordHelper::getCommonTag(Property::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...
79
                        ],
80
                    ]
81
                )
82
            );
83
        } else {
84
            $this->objectPropertyGroups = $data['objectPropertyGroups'];
85
            $this->propertyGroupsToAdd = $data['propertyGroupsToAdd'];
86
        }
87
        return $this->render(
88
            $this->viewFile,
89
            [
90
                'model' => $this->model,
91
                'object' => $this->object,
92
                'object_property_groups' => $this->objectPropertyGroups,
93
                'property_groups_to_add' => $this->propertyGroupsToAdd,
94
                'form' => $this->form,
95
                'widget_id' => $this->getId(),
96
            ]
97
        );
98
    }
99
}
100