ScheduleTime::dayOfWeek()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace WITR\Schedule;
4
5
use Carbon\Carbon;
6
7
class ScheduleTime
8
{
9
10
    protected $datetime;
11
12
    public static function now()
13
    {
14
        return ScheduleTime::fromDate(Carbon::now('America/New_York'));
15
    }
16
17
    public static function setTestNow($now)
18
    {
19
        Carbon::setTestNow($now);
20
    }
21
22
    public function value()
23
    {
24
        return $this->datetime;
25
    }
26
27
    public static function fromDate($datetime)
28
    {
29
        $scheduleTime = new ScheduleTime();
30
31
        $scheduleTime->datetime = $datetime;
32
33
        return $scheduleTime;
34
    }
35
36
    public function dayOfWeek()
37
    {
38
        $day = $this->datetime->dayOfWeek;
39
        if ($this->datetime->hour < 1)
40
        {
41
            $day--;
42
        }
43
        return $day;
44
    }
45
46
    public function hour()
47
    {
48
        $hour = $this->datetime->hour;
49
        if ($hour == 0) {
50
            return 24;
51
        } else {
52
            return $hour;
53
        }
54
    }
55
56
    public function __get($name)
57
    {
58
        if ($name == 'dayOfWeek')
59
        {
60
            return $this->dayOfWeek();
61
        }
62
        return $this->datetime->$name;
63
    }
64
65
    public function __call($method, $arguments)
66
    {
67
        if (method_exists($this, $method))
68
        {
69
            return $this->$method();
70
        }
71
        call_user_func_array(array($this->datetime, $method), $arguments);
72
        return $this;
73
    }
74
}
75