| Conditions | 18 |
| Paths | 1440 |
| Total Lines | 68 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | 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 |
||
| 100 | public function toString() { |
||
| 101 | $text = ''; |
||
| 102 | |||
| 103 | // Min/max stay length constraint variables. |
||
| 104 | $minimum_stay = empty($this->min_days) ? '' : (($this->min_days == 1) ? '@count day' : '@count days'); |
||
| 105 | $maximum_stay = empty($this->max_days) ? '' : (($this->max_days == 1) ? '@count day' : '@count days'); |
||
| 106 | |||
| 107 | // Day of the week constraint variable. |
||
| 108 | $day_of_the_week = $this->getWeekDay($this->checkin_day); |
||
| 109 | |||
| 110 | // Date range constraint variables. |
||
| 111 | $start_date = $this->start_date->format('Y-m-d'); |
||
| 112 | $end_date = $this->end_date->format('Y-m-d'); |
||
| 113 | |||
| 114 | // Next create replacement placeholders to be used in t() below. |
||
| 115 | $args = array( |
||
| 116 | '@minimum_stay' => $minimum_stay, |
||
| 117 | '@maximum_stay' => $maximum_stay, |
||
| 118 | '@start_date' => $start_date, |
||
| 119 | '@end_date' => $end_date, |
||
| 120 | '@day_of_the_week' => $day_of_the_week, |
||
| 121 | ); |
||
| 122 | |||
| 123 | // Finally, build out the constraint text string adding components |
||
| 124 | // as necessary. |
||
| 125 | |||
| 126 | // Specify a date range constraint. |
||
| 127 | if ($start_date && $end_date) { |
||
| 128 | $text = 'From @start_date to @end_date'; |
||
| 129 | } |
||
| 130 | |||
| 131 | // Specify the day of the week constraint. |
||
| 132 | if ($day_of_the_week) { |
||
| 133 | if ($start_date && $end_date) { |
||
| 134 | $text = 'From @start_date to @end_date, if booking starts on @day_of_the_week'; |
||
| 135 | } |
||
| 136 | else { |
||
| 137 | $text = 'If booking starts on @day_of_the_week'; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | // Specify the min/max stay length constraint. |
||
| 142 | if ($minimum_stay || $maximum_stay) { |
||
| 143 | if (empty($text)) { |
||
| 144 | $text = 'The stay '; |
||
| 145 | } |
||
| 146 | else { |
||
| 147 | $text .= ' the stay '; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | if ($minimum_stay && $maximum_stay) { |
||
| 151 | // Special case when min stay and max stay are the same. |
||
| 152 | if ($minimum_stay == $maximum_stay) { |
||
| 153 | $text .= 'must be for @minimum_stay'; |
||
| 154 | } |
||
| 155 | else { |
||
| 156 | $text .= 'must be at least @minimum_stay and at most @maximum_stay'; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | elseif ($minimum_stay) { |
||
| 160 | $text .= 'must be for at least @minimum_stay'; |
||
| 161 | } |
||
| 162 | elseif ($maximum_stay) { |
||
| 163 | $text .= 'cannot be more than @maximum_stay'; |
||
| 164 | } |
||
| 165 | |||
| 166 | return array('text' => $text, 'args' => $args); |
||
| 167 | } |
||
| 168 | |||
| 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..