TermRelationship   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 4
dl 48
loc 48
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 4 4 1
A rules() 7 7 1
A attributeLabels() 7 7 1
A getPost() 4 4 1
A getTerm() 4 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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace common\models;
9
10
use Yii;
11
use yii\db\ActiveRecord;
12
13
/**
14
 * This is the model class for table "{{%term_relationship}}".
15
 *
16
 * @property integer $post_id
17
 * @property integer $term_id
18
 *
19
 * @property Post $post
20
 * @property Term $term
21
 *
22
 * @author  Agiel K. Saputra <[email protected]>
23
 * @since   0.1.0
24
 */
25 View Code Duplication
class TermRelationship extends ActiveRecord
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    /**
28
     * @inheritdoc
29
     */
30
    public static function tableName()
31
    {
32
        return '{{%term_relationship}}';
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function rules()
39
    {
40
        return [
41
            [['post_id', 'term_id'], 'required'],
42
            [['post_id', 'term_id'], 'integer'],
43
        ];
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function attributeLabels()
50
    {
51
        return [
52
            'post_id' => Yii::t('writesdown', 'Post ID'),
53
            'term_id' => Yii::t('writesdown', 'Term ID'),
54
        ];
55
    }
56
57
    /**
58
     * @return \yii\db\ActiveQuery
59
     */
60
    public function getPost()
61
    {
62
        return $this->hasOne(Post::className(), ['id' => 'post_id']);
63
    }
64
65
    /**
66
     * @return \yii\db\ActiveQuery
67
     */
68
    public function getTerm()
69
    {
70
        return $this->hasOne(Term::className(), ['id' => 'term_id']);
71
    }
72
}
73