Passed
Push — master ( ccd18c...cdfc25 )
by Andrii
07:58
created

Consumption::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\server\models;
4
5
/**
6
 * Class Consumption
7
 *
8
 * @property string $type
9
 * @property float[] $value
10
 * @property float[] $overuse
11
 */
12
class Consumption extends \hipanel\base\Model
13
{
14
    use \hipanel\base\ModelTrait;
15
16
    public function rules()
17
    {
18
        return [
19
            [['id', 'object_id'], 'integer'],
20
            [['value', 'overuse'], 'safe'],
21
            [['type', 'limit', 'time', 'unit', 'action_unit', 'currency'], 'string'],
22
            [['price'], 'number'],
23
        ];
24
    }
25
26
    public function getCurrentValue(): ?string
27
    {
28
        return $this->value[$this->getCurrent()];
29
    }
30
31
    public function getCurrentOveruse(): ?string
32
    {
33
        return $this->overuse[$this->getCurrent()];
34
    }
35
36
    public function getPreviousValue(): ?string
37
    {
38
        return $this->value[$this->getPrevious()];
39
    }
40
41
    public function getPreviousOveruse(): ?string
42
    {
43
        return $this->overuse[$this->getPrevious()];
44
    }
45
46
    private function getCurrent(): string
47
    {
48
        return date('m');
49
    }
50
51
    private function getPrevious(): string
52
    {
53
        return date('m', strtotime('-1month'));
54
    }
55
}
56