Passed
Push — master ( 7ba57e...634515 )
by Paweł
03:13
created

FromToDateTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setFrom() 0 5 1
A getFrom() 0 3 1
A setTo() 0 5 1
A getTo() 0 3 1
A throwExceptionIfFromToAreNotSet() 0 4 3
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 2019-01-24
6
 */
7
8
namespace app\components\stats\traits;
9
10
11
use Carbon\Carbon;
12
use yii\base\InvalidConfigException;
13
14
trait FromToDateTrait
15
{
16
    /**
17
     * @var \Carbon\Carbon
18
     */
19
    protected $from;
20
21
    /**
22
     * @var \Carbon\Carbon
23
     */
24
    protected $to;
25
26
    public function setFrom(Carbon $date)
27
    {
28
        $this->from = $date;
29
30
        return $this;
31
    }
32
33
    /**
34
     * @return \Carbon\Carbon
35
     */
36
    public function getFrom(): Carbon
37
    {
38
        return $this->from;
39
    }
40
41
    public function setTo(Carbon $to)
42
    {
43
        $this->to = $to;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return \Carbon\Carbon
50
     */
51
    public function getTo(): Carbon
52
    {
53
        return $this->to;
54
    }
55
56
57
    protected function throwExceptionIfFromToAreNotSet()
58
    {
59
        if (!$this->from || !$this->to) {
60
            throw new InvalidConfigException('Properties \'from\' and \'to\' can not be empty.');
61
        }
62
    }
63
}