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

Consumption   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 13
dl 0
loc 42
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentOveruse() 0 3 1
A getPreviousOveruse() 0 3 1
A rules() 0 7 1
A getCurrent() 0 3 1
A getPrevious() 0 3 1
A getCurrentValue() 0 3 1
A getPreviousValue() 0 3 1
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