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.

CalendarResponse   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 127
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addMatch() 0 6 1
A addMiss() 0 10 2
A getIncluded() 0 3 1
A getExcluded() 0 3 1
A getStartDate() 0 3 1
A getEndDate() 0 3 1
A removeFromMatched() 0 10 2
A applyConstraints() 0 5 2
1
<?php
2
3
/**
4
 * @file
5
 * Class CalendarResponse
6
 */
7
8
namespace Roomify\Bat\Calendar;
9
10
use Roomify\Bat\Unit\UnitInterface;
11
use Roomify\Bat\Constraint\Constraint;
12
13
/**
14
 * A CalendarResponse contains the units that are matched or missed following
15
 * a search, together with the reason they are matched or missed.
16
 */
17
class CalendarResponse {
18
19
  const VALID_STATE = 'valid_state';
20
  const INVALID_STATE = 'invalid_state';
21
  const CONSTRAINT = 'constraint';
22
23
  /**
24
   * @var array
25
   */
26
  protected $included_set;
27
28
  /**
29
   * @var array
30
   */
31
  protected $excluded_set;
32
33
  /**
34
   * @var \DateTime
35
   */
36
  protected $start_date;
37
38
  /**
39
   * @var \DateTime
40
   */
41
  protected $end_date;
42
43
  /**
44
   * @var array
45
   */
46
  protected $valid_states;
47
48
  /**
49
   * @param $start_date
50
   * @param $end_date
51
   * @param $valid_states
52
   * @param $included
53
   * @param $excluded
54
   */
55
  public function __construct(\DateTime $start_date, \DateTime $end_date, $valid_states, $included = array(), $excluded = array()) {
56
    $this->start_date = $start_date;
57
    $this->end_date = $end_date;
58
    $this->valid_states = $valid_states;
59
    $this->included_set = $included;
60
    $this->excluded_set = $excluded;
61
  }
62
63
  /**
64
   * @param $unit
65
   * @param $reason
66
   */
67
  public function addMatch(UnitInterface $unit, $reason = '') {
68
    $this->included_set[$unit->getUnitId()] = array(
69
      'unit' => $unit,
70
      'reason' => $reason,
71
    );
72
  }
73
74
  /**
75
   * @param $unit
76
   * @param $reason
77
   */
78
  public function addMiss(UnitInterface $unit, $reason = '', Constraint $constraint = NULL) {
79
    $this->excluded_set[$unit->getUnitId()] = array(
80
      'unit' => $unit,
81
      'reason' => $reason,
82
    );
83
84
    if ($constraint !== NULL) {
85
      $this->excluded_set[$unit->getUnitId()]['constraint'] = $constraint;
86
    }
87
  }
88
89
  /**
90
   * @return array
91
   */
92
  public function getIncluded() {
93
    return $this->included_set;
94
  }
95
96
  /**
97
   * @return array
98
   */
99
  public function getExcluded() {
100
    return $this->excluded_set;
101
  }
102
103
  /**
104
   * @return DateTime
105
   */
106
  public function getStartDate() {
107
    return $this->start_date;
108
  }
109
110
  /**
111
   * @return DateTime
112
   */
113
  public function getEndDate() {
114
    return $this->end_date;
115
  }
116
117
  /**
118
   * @param $unit
119
   * @param $reason
120
   *
121
   * @return bool
122
   */
123
  public function removeFromMatched(UnitInterface $unit, $reason = '', Constraint $constraint = NULL) {
124
    if (isset($this->included_set[$unit->getUnitId()])) {
125
      // Remove a unit from matched and add to the missed set
126
      unset($this->included_set[$unit->getUnitId()]);
127
      $this->addMiss($unit, $reason, $constraint);
128
      return TRUE;
129
    } else {
130
      return FALSE;
131
    }
132
  }
133
134
  /**
135
   * @param $constraints
136
   */
137
  public function applyConstraints($constraints) {
138
    foreach ($constraints as $constraint) {
139
      $constraint->applyConstraint($this);
140
    }
141
  }
142
143
}
144