Passed
Push — master ( dd4450...9a9614 )
by Andrey
05:55
created

ArticleLanguage::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 32
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 65
rs 9.408

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace app\models;
4
5
use Yii;
6
use Itstructure\AdminModule\models\{Language, ActiveRecord};
7
8
/**
9
 * This is the model class for table "articles_language".
10
 *
11
 * @property int $articles_id
12
 * @property int $language_id
13
 * @property string $title
14
 * @property string $description
15
 * @property string $content
16
 * @property string $metaKeys
17
 * @property string $metaDescription
18
 * @property string $created_at
19
 * @property string $updated_at
20
 *
21
 * @property Language $language
22
 * @property Article $article
23
 *
24
 * @package app\models
25
 */
26
class ArticleLanguage extends ActiveRecord
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public static function tableName()
32
    {
33
        return 'articles_language';
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function rules()
40
    {
41
        return [
42
            [
43
                [
44
                    'articles_id',
45
                    'language_id'
46
                ],
47
                'required'
48
            ],
49
            [
50
                [
51
                    'articles_id',
52
                    'language_id'
53
                ],
54
                'integer'
55
            ],
56
            [
57
                [
58
                    'description',
59
                    'content'
60
                ],
61
                'string'
62
            ],
63
            [
64
                [
65
                    'created_at',
66
                    'updated_at'
67
                ],
68
                'safe'
69
            ],
70
            [
71
                [
72
                    'title',
73
                    'metaKeys',
74
                    'metaDescription'
75
                ],
76
                'string',
77
                'max' => 255
78
            ],
79
            [
80
                [
81
                    'articles_id',
82
                    'language_id'
83
                ],
84
                'unique',
85
                'targetAttribute' => ['articles_id', 'language_id']
86
            ],
87
            [
88
                [
89
                    'language_id'
90
                ],
91
                'exist',
92
                'skipOnError' => true,
93
                'targetClass' => Language::class,
94
                'targetAttribute' => ['language_id' => 'id']
95
            ],
96
            [
97
                [
98
                    'articles_id'
99
                ],
100
                'exist',
101
                'skipOnError' => true,
102
                'targetClass' => Article::class,
103
                'targetAttribute' => ['articles_id' => 'id']
104
            ],
105
        ];
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function attributeLabels()
112
    {
113
        return [
114
            'articles_id' => 'Article ID',
115
            'language_id' => 'Language ID',
116
            'title' => Yii::t('app', 'Title'),
117
            'description' => Yii::t('app', 'Description'),
118
            'content' => Yii::t('app', 'Content'),
119
            'metaKeys' => Yii::t('app', 'Meta keys'),
120
            'metaDescription' => Yii::t('app', 'Meta description'),
121
            'created_at' => Yii::t('app', 'Created date'),
122
            'updated_at' => Yii::t('app', 'Updated date'),
123
        ];
124
    }
125
126
    /**
127
     * @return \yii\db\ActiveQuery
128
     */
129
    public function getLanguage()
130
    {
131
        return $this->hasOne(Language::class, [
132
            'id' => 'language_id'
133
        ]);
134
    }
135
136
    /**
137
     * @return \yii\db\ActiveQuery
138
     */
139
    public function getArticle()
140
    {
141
        return $this->hasOne(Article::class, [
142
            'id' => 'articles_id'
143
        ]);
144
    }
145
}
146