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 ( aa6a9b...aca6d7 )
by
unknown
06:15
created

AbstractEvent::saveEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * @file
5
 * Class AbstractEvent
6
 */
7
8
namespace Roomify\Bat\Event;
9
10
use Roomify\Bat\Event\EventInterface;
11
use Roomify\Bat\Store\Store;
12
use Roomify\Bat\EventFormatter\EventFormatter;
13
14
abstract class AbstractEvent implements EventInterface {
15
16
  const BAT_DAY = 'bat_day';
17
  const BAT_HOUR = 'bat_hour';
18
  const BAT_MINUTE = 'bat_minute';
19
  const BAT_HOURLY = 'bat_hourly';
20
  const BAT_DAILY = 'bat_daily';
21
22
  /**
23
   * The booking unit the event is relevant to
24
   * @var int
25
   */
26
  protected $unit_id;
27
28
  /**
29
   * The unit the event is relevant to
30
   */
31
  protected $unit;
32
33
  /**
34
   * The start date for the event.
35
   *
36
   * @var \DateTime
37
   */
38
  protected $start_date;
39
40
  /**
41
   * The end date for the event.
42
   *
43
   * @var \DateTime
44
   */
45
  protected $end_date;
46
47
  /**
48
   * The value associated with this event.
49
   * This can represent an availability state or a pricing value
50
   *
51
   * @var int
52
   */
53
  protected $value;
54
55
  /**
56
   * Returns the value.
57
   *
58
   * @return int
59
   */
60
  public function getValue() {
61
    return $this->value;
62
  }
63
64
  /**
65
   * Set the value.
66
   *
67
   * @param int $value
68
   */
69
  public function setValue($value) {
70
    $this->value = $value;
71
  }
72
73
  /**
74
   * Returns the unit id.
75
   *
76
   * @return int
77
   */
78
  public function getUnitId() {
79
    return $this->unit_id;
80
  }
81
82
  /**
83
   * Set the unit id.
84
   *
85
   * @param int $unit_id
86
   */
87
  public function setUnitId($unit_id) {
88
    $this->unit_id = $unit_id;
89
  }
90
91
  /**
92
   * Returns the start date.
93
   *
94
   * @return DateTime
95
   */
96
  public function getStartDate() {
97
    return clone($this->start_date);
98
  }
99
100
  /**
101
   * Utility function to always give us a standard format for viewing the start date.
102
   * @return mixed
103
   */
104
  public function startDateToString($format = 'Y-m-d H:i') {
105
    return $this->start_date->format($format);
106
  }
107
108
  /**
109
   * Set the start date.
110
   *
111
   * @param DateTime $start_date
112
   */
113
  public function setStartDate(\DateTime $start_date) {
114
    $this->start_date = clone($start_date);
115
  }
116
117
  /**
118
   * Returns the end date.
119
   *
120
   * @return DateTime
121
   */
122
  public function getEndDate() {
123
    return clone($this->end_date);
124
  }
125
126
  /**
127
   * Utility function to always give us a standard format for viewing the end date.
128
   * @return mixed
129
   */
130
  public function endDateToString($format = 'Y-m-d H:i') {
131
    return $this->end_date->format($format);
132
  }
133
134
  /**
135
   * Set the end date.
136
   *
137
   * @param DateTime $end_date
138
   */
139
  public function setEndDate(\DateTime $end_date) {
140
    $this->end_date = clone($end_date);
141
  }
142
143
  /**
144
   * {@inheritdoc}
145
   */
146
  public function startDay($format = 'j') {
147
    return $this->start_date->format($format);
148
  }
149
150
  /**
151
   * {@inheritdoc}
152
   */
153
  public function endDay($format = 'j') {
154
    return $this->end_date->format($format);
155
  }
156
157
  /**
158
   * {@inheritdoc}
159
   */
160
  public function startMonth($format = 'n') {
161
    return $this->start_date->format($format);
162
  }
163
164
  /**
165
   * {@inheritdoc}
166
   */
167
  public function endMonth($format = 'n') {
168
    return $this->end_date->format($format);
169
  }
170
171
  /**
172
   *{@inheritdoc)
173
   */
174
  public function endMonthDate(\DateTime $date) {
175
    // The time is added so that the end date is included
176
    $date_format = $date->format('Y-n-t 23:59:59');
177
    return new \DateTime($date_format);
178
  }
179
180
  /**
181
   * {@inheritdoc}
182
   */
183
  public function startYear($format = 'Y') {
184
    return $this->start_date->format($format);
185
  }
186
187
  /**
188
   * {@inheritdoc}
189
   */
190
  public function endYear($format = 'Y') {
191
    return $this->end_date->format($format);
192
  }
193
194
  /**
195
   * {@inheritdoc}
196
   */
197
  public function startWeek($format = 'W') {
198
    return $this->start_date->format($format);
199
  }
200
201
  /**
202
   * {@inheritdoc}
203
   */
204
  public function endWeek($format = 'W') {
205
    return $this->end_date->format($format);
206
  }
207
208
  /**
209
   * {@inheritdoc}
210
   */
211
  public function startHour($format = 'G') {
212
    return $this->start_date->format($format);
213
  }
214
215
  /**
216
   * {@inheritdoc}
217
   */
218
  public function endHour($format = 'G') {
219
    return $this->end_date->format($format);
220
  }
221
222
  /**
223
   * {@inheritdoc}
224
   */
225
  public function startMinute($format = 'i') {
226
    return $this->start_date->format($format);
227
  }
228
229
  /**
230
   * {@inheritdoc}
231
   */
232
  public function endMinute($format = 'i') {
233
    return $this->end_date->format($format);
234
  }
235
236
  /**
237
   * {@inheritdoc}
238
   */
239
  public function isFirstMonth($date) {
240
    if ($date->format("n") == $this->startMonth() && $date->format("Y") == $this->startYear()) {
241
      return TRUE;
242
    }
243
244
    return FALSE;
245
  }
246
247
  /**
248
   * {@inheritdoc}
249
   */
250
  public function isLastMonth($date) {
251
    if ($date->format("n") == $this->endMonth() && $date->format("Y") == $this->endYear()) {
252
      return TRUE;
253
    }
254
255
    return FALSE;
256
  }
257
258
  /**
259
   * {@inheritdoc}
260
   */
261
  public function isFirstDay($date) {
262
    if (($date->format('j') == $this->startDay()) && ($this->isFirstMonth($date))) {
263
      return TRUE;
264
    }
265
266
    return FALSE;
267
  }
268
269
  /**
270
   * {@inheritdoc}
271
   */
272
  public function isFirstHour($date) {
273
    if ($date->format('G') == $this->startHour() && $this->isFirstDay($date)) {
274
      return TRUE;
275
    }
276
277
    return FALSE;
278
  }
279
280
  /**
281
   * {@inheritdoc}
282
   */
283
  public function isSameYear() {
284
    if ($this->startYear() == $this->endYear()) {
285
      return TRUE;
286
    }
287
288
    return FALSE;
289
  }
290
291
  /**
292
   * {@inheritdoc}
293
   */
294
  public function isSameMonth() {
295
    if (($this->startMonth() == $this->endMonth()) && $this->isSameYear()) {
296
      return TRUE;
297
    }
298
299
    return FALSE;
300
  }
301
302
  /**
303
   * {@inheritdoc}
304
   */
305
  public function isSameDay() {
306
    if (($this->startDay() == $this->endDay()) && $this->isSameMonth()) {
307
      return TRUE;
308
    }
309
310
    return FALSE;
311
  }
312
313
  /**
314
   * {@inheritdoc}
315
   */
316
  public function isSameHour() {
317
    if (($this->startHour() == $this->endHour()) && $this->isSameDay()) {
318
      return TRUE;
319
    }
320
321
    return FALSE;
322
  }
323
324
  /**
325
   * {@inheritdoc}
326
   */
327
  public function diff() {
328
    $interval = $this->start_date->diff($this->end_date);
329
    return $interval;
330
  }
331
332
  /**
333
   * Returns true if the event overlaps at all with the time period within
334
   * the start and end time.
335
   *
336
   * @param \DateTime $start
337
   * @param \DateTime $end
338
   * @return bool
339
   */
340
  public function overlaps(\DateTime $start, \DateTime $end) {
341
    $overlaps = FALSE;
342
343
    if ($this->dateIsEarlier($start) &&
344
      ($this->dateIsInRange($end) || $this->dateIsLater($end))) {
345
      $overlaps = TRUE;
346
    }
347
    elseif ($this->dateIsInRange($start) &&
348
      ($this->dateIsInRange($end) || $this->dateIsLater($end))) {
349
      $overlaps = TRUE;
350
    }
351
352
    return $overlaps;
353
  }
354
355
  /**
356
   * Checks if date supplied is in range of event
357
   *
358
   * @param \DateTime $date
359
   * @return bool
360
   */
361
  public function dateIsInRange(\DateTime $date) {
362
    $dateInRange = FALSE;
363
364
    $t1 = $this->start_date->getTimeStamp();
365
    $t2 = $this->end_date->getTimeStamp();
366
367
    $t3 = $date->getTimeStamp();
368
369
    if (($t3 >= $t1) && ($t3 <= $t2)) {
370
      $dateInRange = TRUE;
371
    }
372
373
    return $dateInRange;
374
  }
375
376
  /**
377
   * Checks if the date supplied starts earlier than our event
378
   * @param \DateTime $date
379
   * @return bool
380
   */
381 View Code Duplication
  public function dateIsEarlier(\DateTime $date) {
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...
382
    $dateEarlier = FALSE;
383
384
    $t1 = $this->start_date->getTimeStamp();
385
386
    $t3 = $date->getTimeStamp();
387
388
    if ($t3 < $t1) {
389
      $dateEarlier = TRUE;
390
    }
391
392
    return $dateEarlier;
393
  }
394
395
  /**
396
   * Checks if the date supplied ends after our event ends
397
   * @param \DateTime $date
398
   * @return bool
399
   */
400 View Code Duplication
  public function dateIsLater(\DateTime $date) {
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...
401
    $dateLater = FALSE;
402
403
    $t2 = $this->end_date->getTimeStamp();
404
405
    $t4 = $date->getTimestamp();
406
407
    if ($t2 < $t4) {
408
      $dateLater = TRUE;
409
    }
410
411
    return $dateLater;
412
  }
413
414
  /**
415
   * Checks if our event ends after the date supplied
416
   * @param \DateTime $date
417
   * @return bool
418
   */
419 View Code Duplication
  public function endsLater(\DateTime $date) {
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...
420
    $later = FALSE;
421
422
    $t2 = $this->end_date->getTimeStamp();
423
424
    $t4 = $date->getTimestamp();
425
426
    if ($t2 > $t4) {
427
      $later = TRUE;
428
    }
429
430
    return $later;
431
  }
432
433
  /**
434
   * Checks if our event starts earlier than the date supplied
435
   * @param \DateTime $date
436
   * @return bool
437
   */
438 View Code Duplication
  public function startsEarlier(\DateTime $date) {
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...
439
    $earlier = FALSE;
440
441
    $t1 = $this->start_date->getTimeStamp();
442
443
    $t3 = $date->getTimestamp();
444
445
    if ($t1 < $t3) {
446
      $earlier = TRUE;
447
    }
448
449
    return $earlier;
450
  }
451
452
  /**
453
   * Transforms the event in a breakdown of days, hours and minutes with associated states.
454
   *
455
   * @return array
456
   */
457
  public function itemize($itemizer) {
458
    $itemized = $itemizer->itemizeEvent();
459
    return $itemized;
460
  }
461
462
  /**
463
   * Saves an event using the Store object
464
   *
465
   * @param \Roomify\Bat\\Store\Store $store
466
   * @param string $granularity
467
   *
468
   * @return boolean
469
   */
470
  public function saveEvent(Store $store, $granularity = AbstractEvent::BAT_HOURLY) {
471
    return $store->storeEvent($this, $granularity);
0 ignored issues
show
Compatibility introduced by
$this of type object<Roomify\Bat\Event\AbstractEvent> is not a sub-type of object<Roomify\Bat\Event\Event>. It seems like you assume a child class of the class Roomify\Bat\Event\AbstractEvent to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
472
  }
473
474
  /**
475
   * {@inheritdoc}
476
   */
477
  public function toJson(EventFormatter $event_formatter) {
478
    return $event_formatter->format($this);
479
  }
480
481
}
482