PostComment   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 4
dl 45
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 4 4 1
A rules() 7 7 1
A attributeLabels() 7 7 1
A getCommentPost() 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\helpers\ArrayHelper;
12
13
/**
14
 * This is the model class for table "{{%post_comment}}".
15
 *
16
 * @property integer $post_id
17
 *
18
 * @property Post $commentPost
19
 *
20
 * @author Agiel K. Saputra <[email protected]>
21
 * @since 0.1.0
22
 */
23 View Code Duplication
class PostComment extends BaseComment
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...
24
{
25
    /**
26
     * @var string
27
     */
28
    public $post_title;
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public static function tableName()
34
    {
35
        return '{{%post_comment}}';
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function rules()
42
    {
43
        return ArrayHelper::merge(parent::rules(), [
44
            ['post_id', 'required'],
45
            ['post_id', 'integer'],
46
        ]);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function attributeLabels()
53
    {
54
        return ArrayHelper::merge(parent::attributeLabels(), [
55
            'post_id' => Yii::t('writesdown', 'Comment to'),
56
            'post_title' => Yii::t('writesdown', 'Post Title'),
57
        ]);
58
    }
59
60
    /**
61
     * @return \yii\db\ActiveQuery
62
     */
63
    public function getCommentPost()
64
    {
65
        return $this->hasOne(Post::className(), ['id' => 'post_id']);
66
    }
67
}
68