ScheduledShow   A
last analyzed

Complexity

Total Complexity 31

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 31
c 1
b 1
f 0
lcom 2
cbo 2
dl 0
loc 163
rs 9.8

23 Methods

Rating   Name   Duplication   Size   Complexity  
A fromShowAndDJ() 0 9 1
A dj() 0 4 1
A djId() 0 4 1
A show() 0 4 1
A showId() 0 4 1
A djPicture() 0 4 1
A showPicture() 0 4 1
A sliderPicture() 0 4 1
A sliderStyle() 0 4 1
A startsAt() 0 6 1
A start() 0 4 1
A end() 0 4 1
A extendShowByHour() 0 4 1
A timespan() 0 7 3
A hourAdjusted() 0 7 2
A airsDayOfWeek() 0 4 1
A getAirDate() 0 4 1
A getRelativeAirDate() 0 16 3
A airDayOfWeek() 0 4 1
A showDescription() 0 4 1
A setId() 0 4 1
A id() 0 4 1
A nowPlaying() 0 16 4
1
<?php
2
3
namespace WITR\Schedule;
4
5
use WITR\Show;
6
use WITR\User;
7
use Carbon\Carbon;
8
9
class ScheduledShow
10
{
11
12
    protected $show;
13
    protected $dj;
14
    protected $startingHour;
15
    protected $endingHour;
16
    protected $id;
17
    protected $dayOfWeek;
18
19
    public static function fromShowAndDJ($show, $dj)
20
    {
21
        $scheduledShow = new ScheduledShow();
22
23
        $scheduledShow->show = $show;
24
        $scheduledShow->dj = $dj;
25
26
        return $scheduledShow;
27
    }
28
29
    public function dj()
30
    {
31
        return $this->dj->name;
32
    }
33
34
    public function djId()
35
    {
36
        return $this->dj->id;
37
    }
38
39
    public function show()
40
    {
41
        return $this->show->name;
42
    }
43
44
    public function showId()
45
    {
46
        return $this->show->id;
47
    }
48
49
    public function djPicture()
50
    {
51
        return $this->dj->picture;
52
    }
53
54
    public function showPicture()
55
    {
56
        return $this->show->show_picture;
57
    }
58
59
    public function sliderPicture()
60
    {
61
        return $this->show->slider_picture;
62
    }
63
64
    public function sliderStyle()
65
    {
66
        return $this->show->style;
67
    }
68
69
    public function startsAt($startingHour)
70
    {
71
        $this->startingHour = $startingHour;
72
        $this->endingHour = $startingHour;
73
        $this->extendShowByHour();
74
    }
75
76
    public function start()
77
    {
78
        return $this->startingHour;
79
    }
80
81
    public function end()
82
    {
83
        return $this->endingHour;
84
    }
85
86
    public function extendShowByHour()
87
    {
88
        $this->endingHour++;
89
    }
90
91
    public function timespan()
92
    {
93
        $suffix = $this->endingHour < 12 || $this->endingHour > 24 ? 'AM' : 'PM';
94
        $endingHour = $this->hourAdjusted($this->endingHour);
95
        $startingHour = $this->hourAdjusted($this->startingHour);
96
        return $startingHour . ' - ' . $endingHour . ' ' . $suffix;
97
    }
98
99
    private function hourAdjusted($hour)
100
    {
101
        while ($hour > 12) {
102
            $hour -= 12;
103
        }
104
        return $hour;
105
    }
106
107
    public function airsDayOfWeek($airsDayOfWeek)
108
    {
109
        $this->dayOfWeek = $airsDayOfWeek;
110
    }
111
112
    public function getAirDate()
113
    {
114
        return Weekday::display($this->dayOfWeek);
115
    }
116
117
    public function getRelativeAirDate()
118
    {
119
        $now = ScheduleTime::now();
120
        if ($this->dayOfWeek == $now->dayOfWeek)
0 ignored issues
show
Documentation introduced by
The property dayOfWeek does not exist on object<WITR\Schedule\ScheduleTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
        {
122
            return 'Today';
123
        }
124
        else if ($this->dayOfWeek == $now->addDay()->dayOfWeek)
0 ignored issues
show
Documentation Bug introduced by
The method addDay does not exist on object<WITR\Schedule\ScheduleTime>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
125
        {
126
            return 'Tomorrow';
127
        }
128
        else 
129
        {
130
            return $this->getAirDate();
131
        }
132
    }
133
134
135
    public function airDayOfWeek()
136
    {
137
        return $this->dayOfWeek;
138
    }
139
140
    public function showDescription()
141
    {
142
        return $this->show->description;
143
    }
144
145
    public function setId($id)
146
    {
147
        $this->id = $id;
148
    }
149
150
    public function id()
151
    {
152
        return $this->id;
153
    }
154
155
    public function nowPlaying()
156
    {
157
        $today = ScheduleTime::now();
158
159
        if ($this->airDayOfWeek() != $today->dayOfWeek())
160
        {
161
            return false;
162
        }
163
164
        if ($this->startingHour > $today->hour() || $this->endingHour <= $today->hour())
165
        {
166
            return false;
167
        }
168
169
        return true;
170
    }
171
}
172