GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4b510d...1b4781 )
by Dragos
12:48
created

Time::setMinutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Speicher210\BusinessHours;
4
5
/**
6
 * Represents a time.
7
 */
8
class Time implements \JsonSerializable
9
{
10
    /**
11
     * The hours part of the time.
12
     *
13
     * @var integer
14
     */
15
    protected $hours;
16
17
    /**
18
     * The minutes part of the time.
19
     *
20
     * @var integer
21
     */
22
    protected $minutes = 0;
23
24
    /**
25
     * The seconds part of the time.
26
     *
27
     * @var integer
28
     */
29
    protected $seconds = 0;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param integer $hours The hours.
35
     * @param integer $minutes The minutes.
36
     * @param integer $seconds The seconds.
37
     */
38
    public function __construct($hours, $minutes = 0, $seconds = 0)
39
    {
40
        $this->setHours($hours);
41
        $this->setMinutes($minutes);
42
        $this->setSeconds($seconds);
43
    }
44
45
    /**
46
     * Creates a new time from a string.
47
     *
48
     * @param string $time
49
     * @return Time
50
     * @throws \InvalidArgumentException If the passed time is invalid.
51
     */
52
    public static function fromString($time)
53
    {
54
        if (empty($time)) {
55
            throw new \InvalidArgumentException('Invalid time "".');
56
        }
57
58
        try {
59
            $date = new \DateTime($time);
60
        } catch (\Exception $e) {
61
            throw new \InvalidArgumentException(sprintf('Invalid time "%s".', $time), 0, $e);
62
        }
63
64
        $return = static::fromDate($date);
65
        if (strpos($time, '24') === 0) {
66
            $return->setHours(24);
67
        }
68
69
        return $return;
70
    }
71
72
    /**
73
     * Creates a new time from a date.
74
     *
75
     * @param \DateTime $date
76
     * @return Time
77
     */
78
    public static function fromDate(\DateTime $date)
79
    {
80
        return new static($date->format('H'), $date->format('i'), $date->format('s'));
81
    }
82
83
    /**
84
     * Checks if this time is before or equal to an other time.
85
     *
86
     * @param Time $other The time to compare it against.
87
     * @return boolean
88
     */
89
    public function isBeforeOrEqual(Time $other)
90
    {
91
        return $this->toInteger() <= $other->toInteger();
92
    }
93
94
    /**
95
     * Checks if this time is after or equal to an other time.
96
     *
97
     * @param Time $other The time to compare it against.
98
     * @return boolean
99
     */
100
    public function isAfterOrEqual(Time $other)
101
    {
102
        return $this->toInteger() >= $other->toInteger();
103
    }
104
105
    /**
106
     * Check if this time is equal to another time.
107
     *
108
     * @param Time $other The time to compare it against.
109
     * @return boolean
110
     */
111
    public function isEqual(Time $other)
112
    {
113
        return $this->toInteger() === $other->toInteger();
114
    }
115
116
    /**
117
     * Get the integer representation of the time.
118
     *
119
     * @return integer
120
     */
121
    public function toInteger()
122
    {
123
        return (int)sprintf('%d%02d%02d', $this->hours, $this->minutes, $this->seconds);
124
    }
125
126
    /**
127
     * Set the hours.
128
     *
129
     * @param integer $hours The hours.
130
     * @return Time
131
     */
132 View Code Duplication
    public function setHours($hours)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
    {
134
        $hours = (int)$hours;
135
136
        $this->timeElementsAreValid($hours, $this->minutes, $this->seconds);
137
138
        $this->hours = (int)$hours;
139
140
        return $this;
141
    }
142
143
    /**
144
     * Get the hours.
145
     *
146
     * @return integer
147
     */
148
    public function getHours()
149
    {
150
        return $this->hours;
151
    }
152
153
    /**
154
     * Set the minutes.
155
     *
156
     * @param integer $minutes The minutes
157
     * @return Time
158
     */
159 View Code Duplication
    public function setMinutes($minutes)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
160
    {
161
        $minutes = (int)$minutes;
162
163
        $this->timeElementsAreValid($this->hours, $minutes, $this->seconds);
164
165
        $this->minutes = (int)$minutes;
166
167
        return $this;
168
    }
169
170
    /**
171
     * Get the minutes.
172
     *
173
     * @return integer
174
     */
175
    public function getMinutes()
176
    {
177
        return $this->minutes;
178
    }
179
180
    /**
181
     * Set the seconds.
182
     *
183
     * @param integer $seconds The seconds.
184
     * @return Time
185
     */
186 View Code Duplication
    public function setSeconds($seconds)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
    {
188
        $seconds = (int)$seconds;
189
190
        $this->timeElementsAreValid($this->hours, $this->minutes, $seconds);
191
192
        $this->seconds = (int)$seconds;
193
194
        return $this;
195
    }
196
197
    /**
198
     * Get the seconds.
199
     *
200
     * @return integer
201
     */
202
    public function getSeconds()
203
    {
204
        return $this->seconds;
205
    }
206
207
    /**
208
     * Check if the time elements are valid.
209
     *
210
     * @param integer $hours The hours.
211
     * @param integer $minutes The minutes.
212
     * @param integer $seconds The seconds.
213
     * @return boolean
214
     * @throws \InvalidArgumentException If the elements are not valid.
215
     */
216
    private function timeElementsAreValid($hours, $minutes, $seconds)
217
    {
218
        $exception = new \InvalidArgumentException(
219
            sprintf('Invalid time "%02d:%02d:%02d".', $hours, $minutes, $seconds)
220
        );
221
222
        if ((int)sprintf('%d%02d%02d', $hours, $minutes, $seconds) > 240000) {
223
            throw $exception;
224
        } elseif ($hours < 0 || $minutes < 0 || $seconds < 0) {
225
            throw $exception;
226
        } elseif ($hours <= 24 && $minutes <= 59 && $seconds <= 59) {
227
            return true;
228
        }
229
230
        throw $exception;
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     */
236
    public function jsonSerialize()
237
    {
238
        return array(
239
            'hours' => $this->hours,
240
            'minutes' => $this->minutes,
241
            'seconds' => $this->seconds,
242
        );
243
    }
244
245
    /**
246
     * Returns a string representation of the time.
247
     *
248
     * @return string
249
     */
250
    public function __toString()
251
    {
252
        return sprintf('%02d:%02d:%02d', $this->hours, $this->minutes, $this->seconds);
253
    }
254
}
255