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.

ObjectPropertyGroup   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 15.52 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 9
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A rules() 0 8 1
A attributeLabels() 9 9 1
A getForModel() 0 14 1
A getGroup() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace app\models;
4
5
use Yii;
6
use yii\db\ActiveRecord;
7
8
/**
9
 * This is the model class for table "object_property_group".
10
 *
11
 * @property integer $id
12
 * @property integer $object_id
13
 * @property integer $object_model_id
14
 * @property integer $property_group_id
15
 */
16
class ObjectPropertyGroup extends ActiveRecord
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public static function tableName()
22
    {
23
        return '{{%object_property_group}}';
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function rules()
30
    {
31
        return [
32
            [['object_id', 'object_model_id', 'property_group_id'], 'required'],
33
            [['object_id', 'object_model_id', 'property_group_id'], 'integer'],
34
            [['object_id', 'object_model_id', 'property_group_id'], 'unique', 'targetAttribute' => ['object_id', 'object_model_id', 'property_group_id'], 'message' => 'Property group is already binded'],
35
        ];
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 View Code Duplication
    public function attributeLabels()
42
    {
43
        return [
44
            'id' => Yii::t('app', 'ID'),
45
            'object_id' => Yii::t('app', 'Object ID'),
46
            'object_model_id' => Yii::t('app', 'Object Model ID'),
47
            'property_group_id' => Yii::t('app', 'Property Group ID'),
48
        ];
49
    }
50
51
    public static function getForModel($model)
52
    {
53
        /** @var BaseObject $object */
54
        $object = BaseObject::getForClass(get_class($model));
55
        return ObjectPropertyGroup::find()
56
            ->joinWith('group')
57
            ->where(
58
                [
59
                    static::tableName() . '.object_id' => $object->id,
60
                    static::tableName() . '.object_model_id' => $model->id,
61
                ]
62
            )->orderBy(PropertyGroup::tableName() . '.sort_order')
63
            ->all();
64
    }
65
66
    /**
67
     * @return PropertyGroup|null
0 ignored issues
show
Documentation introduced by
Should the return type not be \yii\db\ActiveQuery?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
68
     */
69
    public function getGroup()
70
    {
71
        return $this->hasOne(PropertyGroup::className(), ['id' => 'property_group_id']);
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...
72
    }
73
}
74
?>