UserHasFlow   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 51
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 4 4 1
A rules() 10 10 1
A attributeLabels() 7 7 1
A getUser() 4 4 1
A getFlow() 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
namespace app\models;
4
5
use Yii;
6
7
/**
8
 * This is the model class for table "user_has_flow".
9
 *
10
 * @property string $user_username
11
 * @property int $flow_id
12
 * @property User $userUsername
13
 * @property Flow $flow
14
 */
15 View Code Duplication
class UserHasFlow extends \yii\db\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...
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public static function tableName()
21
    {
22
        return 'user_has_flow';
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function rules()
29
    {
30
        return [
31
            [['user_username', 'flow_id'], 'required'],
32
            [['flow_id'], 'integer'],
33
            [['user_username'], 'string', 'max' => 64],
34
            [['user_username'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_username' => 'username']],
35
            [['flow_id'], 'exist', 'skipOnError' => true, 'targetClass' => Flow::class, 'targetAttribute' => ['flow_id' => 'id']],
36
        ];
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function attributeLabels()
43
    {
44
        return [
45
            'user_username' => Yii::t('app', 'Username'),
46
            'flow_id' => Yii::t('app', 'Flow ID'),
47
        ];
48
    }
49
50
    /**
51
     * @return \yii\db\ActiveQuery
52
     */
53
    public function getUser()
54
    {
55
        return $this->hasOne(User::class, ['username' => 'user_username']);
56
    }
57
58
    /**
59
     * @return \yii\db\ActiveQuery
60
     */
61
    public function getFlow()
62
    {
63
        return $this->hasOne(Flow::class, ['id' => 'flow_id']);
64
    }
65
}
66