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 ( c9db31...f3227f )
by
unknown
03:02
created

CheckInDayConstraint::setCheckinDay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
140
  }
141
142
  /**
143
   * @param $checkin_day
144
   */
145
  public function setCheckinDay($checkin_day) {
146
    $this->checkin_day = $checkin_day;
147
  }
148
149
}
150