MediaTag   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A getMedia() 0 3 1
A attributeLabels() 0 6 1
A getTag() 0 3 1
A find() 0 3 1
A tableName() 0 3 1
A behaviors() 0 6 1
1
<?php
2
3
namespace app\models;
4
5
use yii\behaviors\TimestampBehavior;
6
use yii\db\ActiveRecord;
7
use yii\helpers\ArrayHelper;
8
9
/**
10
 * This is the model class for table "media_tag".
11
 *
12
 * @property int $media_id
13
 * @property int $tag_id
14
 * @property string $created_at
15
 *
16
 * @property Media $media
17
 * @property Tag $tag
18
 */
19
class MediaTag extends ActiveRecord
20
{
21
22
    public function behaviors()
23
    {
24
        return ArrayHelper::merge(parent::behaviors(), [
25
            'time' => [
26
                'class' => TimestampBehavior::class,
27
                'updatedAtAttribute' => false,
28
            ],
29
        ]);
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public static function tableName()
36
    {
37
        return 'media_tag';
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function rules()
44
    {
45
        return [
46
            [['media_id', 'tag_id'], 'required'],
47
            [['media_id', 'tag_id'], 'integer'],
48
            [['created_at'], 'safe'],
49
            [['media_id', 'tag_id'], 'unique', 'targetAttribute' => ['media_id', 'tag_id']],
50
            [['media_id'], 'exist', 'skipOnError' => true, 'targetClass' => Media::class, 'targetAttribute' => ['media_id' => 'id']],
51
            [['tag_id'], 'exist', 'skipOnError' => true, 'targetClass' => Tag::class, 'targetAttribute' => ['tag_id' => 'id']],
52
        ];
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function attributeLabels()
59
    {
60
        return [
61
            'media_id' => 'Media ID',
62
            'tag_id' => 'Tag ID',
63
            'created_at' => 'Created At',
64
        ];
65
    }
66
67
    /**
68
     * @return \yii\db\ActiveQuery
69
     */
70
    public function getMedia()
71
    {
72
        return $this->hasOne(Media::class, ['id' => 'media_id']);
73
    }
74
75
    /**
76
     * @return \yii\db\ActiveQuery
77
     */
78
    public function getTag()
79
    {
80
        return $this->hasOne(Tag::class, ['id' => 'tag_id']);
81
    }
82
83
    /**
84
     * @inheritdoc
85
     * @return MediaTagQuery the active query used by this AR class.
86
     */
87
    public static function find()
88
    {
89
        return new MediaTagQuery(get_called_class());
90
    }
91
}
92