Minutes   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 113
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
A calculateStartEnd() 0 10 2
A getEnd() 0 4 1
A getMinutes() 0 4 1
A getStart() 0 4 1
A make() 0 4 1
A setEnd() 0 4 1
A setStart() 0 4 1
A setToday() 0 6 1
1
<?php
2
3
namespace PragmaRX\Tracker\Support;
4
5
use Carbon\Carbon;
6
7
class Minutes
8
{
9
    /**
10
     * @var
11
     */
12
    private $minutes;
13
14
    /**
15
     * @var
16
     */
17
    private $start;
18
19
    /**
20
     * @var
21
     */
22
    private $end;
23
24
    /**
25
     * Minutes constructor.
26
     *
27
     * @param $minutes
28
     */
29
    public function __construct($minutes = null)
30
    {
31
        if (!isset($minutes)) {
32
            return;
33
        }
34
35
        $this->minutes = $minutes;
36
37
        if ($minutes instanceof self) {
38
            $this->start = $minutes->getStart();
39
40
            $this->end = $minutes->getEnd();
41
        } else {
42
            $this->calculateStartEnd();
43
        }
44
    }
45
46
    /**
47
     * Calculate start and end dates.
48
     */
49
    private function calculateStartEnd()
50
    {
51
        if ($this->minutes == 0) {
52
            $this->setToday();
53
        } else {
54
            $this->start = Carbon::now()->subMinutes($this->minutes);
55
56
            $this->end = Carbon::now();
57
        }
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63
    public function getEnd()
64
    {
65
        return $this->end;
66
    }
67
68
    /**
69
     * @return mixed
70
     */
71
    public function getMinutes()
72
    {
73
        return $this->minutes;
74
    }
75
76
    /**
77
     * @return mixed
78
     */
79
    public function getStart()
80
    {
81
        return $this->start;
82
    }
83
84
    /**
85
     * @param $minutes
86
     *
87
     * @return static
88
     */
89
    public static function make($minutes)
90
    {
91
        return new static($minutes);
92
    }
93
94
    /**
95
     * @param mixed $end
96
     */
97
    public function setEnd($end)
98
    {
99
        $this->end = $end;
100
    }
101
102
    /**
103
     * @param mixed $start
104
     */
105
    public function setStart($start)
106
    {
107
        $this->start = $start;
108
    }
109
110
    /**
111
     * Today.
112
     */
113
    private function setToday()
114
    {
115
        $this->start = Carbon::now()->setTime(0, 0, 0);
116
117
        $this->end = Carbon::now()->setTime(23, 59, 59);
118
    }
119
}
120