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 ( 24f210...86539e )
by
unknown
15:03
created

CheckInDayConstraint::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
3
/**
4
 * @file
5
 * Class CheckInDayConstraint
6
 */
7
8
namespace Roomify\Bat\Constraint;
9
10
use Roomify\Bat\Calendar\CalendarResponse;
11
use Roomify\Bat\Constraint\Constraint;
12
13
/**
14
 *
15
 */
16
class CheckInDayConstraint extends Constraint {
17
18
  /**
19
   * @var
20
   */
21
  protected $checkin_day;
22
23
  /**
24
   * @param $units
25
   * @param $checkin_day
26
   */
27
  public function __construct($units, $checkin_day, $start_date = NULL, $end_date = NULL) {
28
    parent::__construct($units);
29
30
    $this->checkin_day = $checkin_day;
31
    $this->start_date = $start_date;
32
    $this->end_date = $end_date;
33
  }
34
35
  /**
36
   * {@inheritdoc}
37
   */
38
  public function applyConstraint(CalendarResponse &$calendar_response) {
39
    parent::applyConstraint($calendar_response);
40
41
    if ($this->start_date === NULL) {
42
      $this->start_date = new \DateTime('1970-01-01');
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime('1970-01-01') of type object<DateTime> is incompatible with the declared type object<Roomify\Bat\Constraint\DateTime> of property $start_date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
    }
44
    if ($this->end_date === NULL) {
45
      $this->end_date = new \DateTime('2999-12-31');
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime('2999-12-31') of type object<DateTime> is incompatible with the declared type object<Roomify\Bat\Constraint\DateTime> of property $end_date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
    }
47
48
    if ($this->start_date->getTimestamp() <= $calendar_response->getStartDate()->getTimestamp() &&
49
        $this->end_date->getTimestamp() >= $calendar_response->getEndDate()->getTimestamp() &&
50
        $this->checkin_day != $calendar_response->getStartDate()->format('N')) {
51
52
      $units = $this->getUnits();
53
54
      $included_set = $calendar_response->getIncluded();
55
56
      foreach ($included_set as $unit_id => $set) {
57
        if (isset($units[$unit_id]) || empty($units)) {
58
          $calendar_response->removeFromMatched($included_set[$unit_id]['unit'], CalendarResponse::INVALID_STATE);
59
60
          $this->affected_units[$unit_id] = $included_set[$unit_id]['unit'];
61
        }
62
      }
63
    }
64
  }
65
66
  /**
67
   * Generates a text describing an availability_constraint.
68
   *
69
   * @return string
70
   *   The formatted message.
71
   */
72
  public function toString() {
73
    $text = '';
74
    $args = array();
75
76
    $start_date = FALSE;
77
    $end_date = FALSE;
78
79
    // Day of the week constraint variable.
80
    $day_of_the_week = $this->getWeekDay($this->checkin_day);
81
82
    // Date range constraint variables.
83
    if ($this->start_date !== NULL) {
84
      $start_date = $this->start_date->format('Y-m-d');
85
    }
86
    if ($this->start_date !== NULL) {
87
      $end_date = $this->end_date->format('Y-m-d');
88
    }
89
90
    // Finally, build out the constraint text string adding components
91
    // as necessary.
92
93
    // Specify a date range constraint.
94 View Code Duplication
    if ($start_date && $end_date) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
95
      $text = 'From @start_date to @end_date';
96
97
      $args['@start_date'] = $start_date;
98
      $args['@end_date'] = $end_date;
99
    }
100
101
    // Specify the day of the week constraint.
102 View Code Duplication
    if ($day_of_the_week) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
103
      if ($start_date && $end_date) {
104
        $text = 'From @start_date to @end_date, if booking starts on @day_of_the_week';
105
      }
106
      else {
107
        $text = 'If booking starts on @day_of_the_week';
108
      }
109
110
      $args['@day_of_the_week'] = $day_of_the_week;
111
    }
112
113
    return array('text' => $text, 'args' => $args);
114
  }
115
116
  /**
117
   * @param $day
118
   * @return string
119
   */
120 View Code Duplication
  private function getWeekDay($day) {
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...
121
    $weekdays = array(
122
      1 => 'Monday',
123
      2 => 'Tuesday',
124
      3 => 'Wednesday',
125
      4 => 'Thursday',
126
      5 => 'Friday',
127
      6 => 'Saturday',
128
      7 => 'Sunday',
129
    );
130
131
    return isset($weekdays[$day]) ? $weekdays[$day] : '';
132
  }
133
134
}
135