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
Pull Request — master (#7)
by
unknown
02:25
created

DateConstraint::applyConstraint()   C

Complexity

Conditions 8
Paths 16

Size

Total Lines 29
Code Lines 14

Duplication

Lines 7
Ratio 24.14 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 29
rs 5.3846
cc 8
eloc 14
nc 16
nop 1
1
<?php
2
3
/**
4
 * @file
5
 * Class DateConstraint
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 DateConstraint extends Constraint {
17
18
  /**
19
   * @param $units
20
   */
21
  public function __construct($units, $start_date = NULL, $end_date = NULL) {
22
    parent::__construct($units);
23
24
    $this->start_date = $start_date;
25
    $this->end_date = $end_date;
26
  }
27
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function applyConstraint(CalendarResponse &$calendar_response) {
32
    parent::applyConstraint($calendar_response);
33
34
    if ($this->start_date === NULL) {
35
      $this->start_date = new \DateTime('1970-01-01');
36
    }
37
    if ($this->end_date === NULL) {
38
      $this->end_date = new \DateTime('2999-12-31');
39
    }
40
41
    // If the constraint start date is on or after the requested start date
42
    // or the constraint end date is on or before the requested end date, mark
43
    // the units as invalid.
44
    if ($this->start_date->getTimestamp() >= $calendar_response->getStartDate()->getTimestamp() ||
45
        $this->end_date->getTimestamp() <= $calendar_response->getEndDate()->getTimestamp()) {
46
47
      $units = $this->getUnits();
48
49
      $included_set = $calendar_response->getIncluded();
50
51 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...
52
        if (isset($units[$unit_id]) || empty($units)) {
53
          $calendar_response->removeFromMatched($included_set[$unit_id]['unit'], CalendarResponse::INVALID_STATE);
54
55
          $this->affected_units[$unit_id] = $included_set[$unit_id]['unit'];
56
        }
57
      }
58
    }
59
  }
60
61
  /**
62
   * Generates a text describing an availability_constraint.
63
   *
64
   * @return string
65
   *   The formatted message.
66
   */
67
  public function toString() {
68
    $text = '';
69
    $args = array();
70
71
    $start_date = FALSE;
72
    $end_date = FALSE;
73
74
    // Date range constraint variables.
75
    if ($this->start_date !== NULL) {
76
      $start_date = $this->start_date->format('Y-m-d');
77
    }
78
    if ($this->start_date !== NULL) {
79
      $end_date = $this->end_date->format('Y-m-d');
80
    }
81
82
    // Specify a date range constraint.
83
    if ($start_date && $end_date) {
84
      $text = 'From @start_date to @end_date';
85
86
      $args['@start_date'] = $start_date;
87
      $args['@end_date'] = $end_date;
88
    }
89
90
    // Specify the start/end constraint.
91
    if ($start_date && $end_date) {
92
      $text = 'From @start_date to @end_date';
93
    }
94
95
    return array('text' => $text, 'args' => $args);
96
  }
97
98
}
99