Completed
Push — master ( 040341...7aaefe )
by Dmitry
04:12
created

Price   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 43.28 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 29
loc 67
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 11 1
A attributeLabels() 12 12 1
A getTypeOptions() 9 9 1
A getUnitOptions() 8 8 1
A getCurrencyOptions() 0 4 1
A getObject() 0 4 1
A getPlan() 0 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 hipanel\modules\finance\models;
4
5
use hipanel\models\Ref;
6
use Yii;
7
8
/**
9
 * Class Price
10
 *
11
 * @property int $id
12
 * @property int $plan_id
13
 * @property string|int $object_id
14
 * @property string|float $price
15
 * @property string $currency
16
 * @property string|int $main_object_id
17
 *
18
 * @property TargetObject $object
19
 * @property Plan $plan
20
 *
21
 * @author Dmytro Naumenko <[email protected]>
22
 */
23
class Price extends \hipanel\base\Model
24
{
25
    use \hipanel\base\ModelTrait;
26
27
    const SCENARIO_CREATE = 'create';
28
    const SCENARIO_UPDATE = 'update';
29
    const SCENARIO_DELETE = 'delete';
30
31
    public function rules()
32
    {
33
        return array_merge(parent::rules(), [
34
            [['id', 'parent_id', 'plan_id', 'object_id', 'type_id', 'unit_id', 'currency_id', 'main_object_id'], 'integer'],
35
            [['type', 'plan_name', 'unit', 'currency', 'note', 'data'], 'string'],
36
            [['quantity', 'price'], 'number'],
37
38
            [['plan_id', 'type', 'price', 'currency'], 'required', 'on' => ['create', 'update']],
39
            [['id'], 'required', 'on' => ['update', 'set-note', 'delete']],
40
        ]);
41
    }
42
43 View Code Duplication
    public function attributeLabels()
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45
        return [
46
            'plan_id' => Yii::t('hipanel:finance', 'Plan'),
47
            'plan' => Yii::t('hipanel:finance', 'Plan'),
48
            'quantity' => Yii::t('hipanel:finance', 'Prepaid'),
49
            'unit' => Yii::t('hipanel:finance', 'Unit'),
50
            'price' => Yii::t('hipanel:finance', 'Price'),
51
            'note' => Yii::t('hipanel', 'Note'),
52
            'type' => Yii::t('hipanel', 'Type'),
53
        ];
54
    }
55
56 View Code Duplication
    public function getTypeOptions()
0 ignored issues
show
Duplication introduced by
This method 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...
57
    {
58
        return Ref::getList('type,bill', null, [
59
            'select' => 'oname_label',
60
            'pnames' => 'monthly,overuse',
61
            'with_recursive' => 1,
62
            'mapOptions' => ['from' => 'oname'],
63
        ]);
64
    }
65
66 View Code Duplication
    public function getUnitOptions()
0 ignored issues
show
Duplication introduced by
This method 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...
67
    {
68
        return Ref::getList('type,unit', null, [
69
            'with_recursive' => 1,
70
            'select' => 'oname_label',
71
            'mapOptions' => ['from' => 'oname'],
72
        ]);
73
    }
74
75
    public function getCurrencyOptions()
76
    {
77
        return Ref::getList('type,currency');
78
    }
79
80
    public function getObject()
81
    {
82
        return $this->hasOne(TargetObject::class, ['id' => 'id']);
83
    }
84
85
    public function getPlan()
86
    {
87
        return $this->hasOne(Plan::class, ['id' => 'plan_id']);
88
    }
89
}
90