Completed
Push — master ( 62d2ea...1993b9 )
by Andrii
11:09
created

Charge   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 11 1
A attributeLabels() 0 9 1
A markAsNotNew() 0 4 1
A getIsNewRecord() 0 4 2
1
<?php
2
3
namespace hipanel\modules\finance\models;
4
5
use Yii;
6
7
class Charge extends \hiqdev\hiart\ActiveRecord
8
{
9
    const SCENARIO_CREATE = 'create';
10
    const SCENARIO_UPDATE = 'update';
11
12
    private $isNewRecord;
13
14
    public function rules()
15
    {
16
        return [
17
            [['id', 'type_id', 'object_id', 'bill_id'], 'integer'],
18
            [['type', 'label', 'ftype'], 'safe'],
19
            [['sum', 'quantity'], 'number'],
20
21
            [['sum', 'type', 'label', 'quantity'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
22
            [['id'], 'safe', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]]
23
        ];
24
    }
25
26
    public function attributeLabels()
27
    {
28
        return array_merge(parent::attributeLabels(), [
29
            'sum' => Yii::t('hipanel', 'Sum'),
30
            'type' => Yii::t('hipanel', 'Type'),
31
            'quantity' => Yii::t('hipanel', 'Quantity'),
32
            'label' => Yii::t('hipanel', 'Description'),
33
        ]);
34
    }
35
36
    public function markAsNotNew()
37
    {
38
        $this->isNewRecord = false;
39
    }
40
41
    public function getIsNewRecord()
42
    {
43
        return $this->isNewRecord !== false && parent::getIsNewRecord();
44
    }
45
}
46