| Conditions | 14 |
| Paths | 24 |
| Total Lines | 38 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 55 | public function applyConstraint(CalendarResponse &$calendar_response) { |
||
| 56 | parent::applyConstraint($calendar_response); |
||
| 57 | |||
| 58 | if ($this->start_date === NULL) { |
||
| 59 | $this->start_date = new \DateTime('1970-01-01'); |
||
|
|
|||
| 60 | } |
||
| 61 | if ($this->end_date === NULL) { |
||
| 62 | $this->end_date = new \DateTime('2999-12-31'); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($this->start_date->getTimestamp() <= $calendar_response->getStartDate()->getTimestamp() && |
||
| 66 | $this->end_date->getTimestamp() >= $calendar_response->getEndDate()->getTimestamp() && |
||
| 67 | ($this->checkin_day === NULL || $this->checkin_day == $calendar_response->getStartDate()->format('N'))) { |
||
| 68 | |||
| 69 | $units = $this->getUnits(); |
||
| 70 | |||
| 71 | $included_set = $calendar_response->getIncluded(); |
||
| 72 | |||
| 73 | foreach ($included_set as $unit_id => $set) { |
||
| 74 | if (isset($units[$unit_id]) || empty($units)) { |
||
| 75 | $start_date = $calendar_response->getStartDate(); |
||
| 76 | $end_date = $calendar_response->getEndDate(); |
||
| 77 | |||
| 78 | $diff = $end_date->diff($start_date)->days; |
||
| 79 | if (is_numeric($this->min_days) && $diff < $this->min_days) { |
||
| 80 | $calendar_response->removeFromMatched($included_set[$unit_id]['unit'], CalendarResponse::CONSTRAINT, $this); |
||
| 81 | |||
| 82 | $this->affected_units[$unit_id] = $included_set[$unit_id]['unit']; |
||
| 83 | } |
||
| 84 | elseif (is_numeric($this->max_days) && $diff > $this->max_days) { |
||
| 85 | $calendar_response->removeFromMatched($included_set[$unit_id]['unit'], CalendarResponse::CONSTRAINT, $this); |
||
| 86 | |||
| 87 | $this->affected_units[$unit_id] = $included_set[$unit_id]['unit']; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 188 |
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..