PriceHistory::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\models;
12
13
use hipanel\base\ModelTrait;
14
15
/**
16
 * Class PlanHistory
17
 *
18
 * @property \DateTime $time
19
 * @property float $old_price
20
 */
21
class PriceHistory extends Price
22
{
23
    use ModelTrait;
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function rules()
29
    {
30
        return array_merge(parent::rules(), [
31
            [['old_price', 'old_quantity'], 'number'],
32
            [['time'], 'date'],
33
        ]);
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function attributeLabels()
40
    {
41
        return array_merge(parent::attributeLabels(), [
42
            'old_price' => \Yii::t('hipanel.finance.price', 'Old price'),
43
            'old_quantity' => \Yii::t('hipanel.finance.price', 'Old quantity'),
44
        ]);
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function isQuantityPredefined(): bool
51
    {
52
        return true;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public static function instantiate($row)
59
    {
60
        return new self([
61
            'time' => $row['time'],
62
            'old_price' => $row['old_price'],
63
            'old_quantity' => $row['old_quantity'],
64
        ]);
65
    }
66
}
67