| Conditions | 18 |
| Paths | 263 |
| Total Lines | 122 |
| Code Lines | 73 |
| Lines | 5 |
| Ratio | 4.1 % |
| Changes | 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 |
||
| 177 | protected function Calendar($weeks, $values, Calendar $currentCalendar) |
||
| 178 | { |
||
| 179 | // 1) Single Values |
||
| 180 | |||
| 181 | $calendar = $values; |
||
| 182 | $calendar['InnerClass'] = $this->innerClass; |
||
| 183 | $calendar['ShowWeekLeft'] = $this->showWeekLeft; |
||
| 184 | $calendar['WeekLeftTitle'] = $this->weekLeftTitle; |
||
| 185 | $calendar['ShowWeekRight'] = $this->showWeekRight; |
||
| 186 | $calendar['WeekRightTitle'] = $this->weekRightTitle; |
||
| 187 | //Hack |
||
| 188 | $week = $weeks[1]['week']; |
||
| 189 | $year = $weeks[1]['yearOfWeek']; |
||
| 190 | $monthTitleDate = $this->getWeekStartDay($week, $year); |
||
| 191 | $calendar['MonthTitle'] = date('F Y', $monthTitleDate); |
||
| 192 | |||
| 193 | // 2) Days Values |
||
| 194 | |||
| 195 | $daysByDateFormat = $this->DaysByDateFormat(); |
||
| 196 | |||
| 197 | if (count($daysByDateFormat) == 0) { |
||
| 198 | return new ArrayData($calendar); |
||
| 199 | } |
||
| 200 | |||
| 201 | View Code Duplication | foreach ($daysByDateFormat as $day) { |
|
| 202 | $dayTitleClass = eval($this->dayTitleClass); |
||
| 203 | $dayTitle = eval($this->dayTitle); |
||
| 204 | $days[] = new ArrayData(array('DayTitleClass' => $dayTitleClass, 'DayTitle' => $dayTitle)); |
||
| 205 | } |
||
| 206 | |||
| 207 | $calendar['Days'] = new ArrayList($days); |
||
| 208 | |||
| 209 | // 3) Weeks Values |
||
| 210 | |||
| 211 | $today = mktime(0, 0, 0, date('n'), date('j'), date('Y')); |
||
| 212 | |||
| 213 | foreach ($weeks as $week) { |
||
| 214 | $period = array(); |
||
| 215 | |||
| 216 | // 1) Single Values |
||
| 217 | |||
| 218 | $period['WeekClass'] = eval($this->weekClass); |
||
| 219 | $period['ShowWeekLeft'] = $this->showWeekLeft; |
||
| 220 | $period['WeekLeft'] = eval($this->weekLeft); |
||
| 221 | $period['ShowWeekRight'] = $this->showWeekRight; |
||
| 222 | $period['WeekRight'] = eval($this->weekRight); |
||
| 223 | |||
| 224 | if ($this->weekLinkView) { |
||
| 225 | $date = $this->getWeekStartDay($week['week'], $week['yearOfWeek']); |
||
| 226 | $linkController = $currentCalendar->getController(); |
||
| 227 | if ($this->weekLinkController) { |
||
| 228 | $linkController = $this->weekLinkController; |
||
| 229 | } |
||
| 230 | $linkCalendar = $currentCalendar; |
||
| 231 | if ($this->weekLinkCalendar) { |
||
| 232 | $linkCalendar = $this->weekLinkCalendar; |
||
| 233 | } |
||
| 234 | $params = $this->weekLinkView->getLinkParams($date); |
||
| 235 | $period['WeekLink'] = $linkCalendar->Link($linkController, $this->weekLinkView, $params); |
||
| 236 | } |
||
| 237 | |||
| 238 | // 2) Days Values |
||
| 239 | |||
| 240 | $days = array(); |
||
| 241 | |||
| 242 | $dates = $this->WeekDates($daysByDateFormat, $week['week'], $week['yearOfWeek']); |
||
| 243 | |||
| 244 | foreach ($dates as $date) { |
||
| 245 | $day = date('j', $date); |
||
| 246 | $month = date('n', $date); |
||
| 247 | $year = date('Y', $date); |
||
| 248 | |||
| 249 | $dateParams = array(); |
||
| 250 | |||
| 251 | $dateParams['IsToday'] = $date == $today; |
||
| 252 | $dateParams['IsPast'] = $date < $today; |
||
| 253 | if ($month == $week['month']) { |
||
| 254 | $dateParams['CurrentMonth'] = true; |
||
| 255 | } elseif (($year == $week['yearOfMonth'] && $month < $week['month']) || ($year == $week['yearOfMonth'] - 1 && $month == 12)) { |
||
| 256 | $dateParams['PrevMonth'] = true; |
||
| 257 | if ($year == $week['yearOfMonth'] - 1) { |
||
| 258 | $dateParams['PrevYear'] = true; |
||
| 259 | } |
||
| 260 | } else { |
||
| 261 | $dateParams['NextMonth'] = true; |
||
| 262 | if ($year == $week['yearOfMonth'] + 1) { |
||
| 263 | $dateParams['NextYear'] = true; |
||
| 264 | } |
||
| 265 | } |
||
| 266 | |||
| 267 | $dateParams['DayClass'] = eval($this->dayClass); |
||
| 268 | $dateParams['Day'] = $day; |
||
| 269 | |||
| 270 | if ($this->dayLinkView) { |
||
| 271 | $linkController = $currentCalendar->getController(); |
||
| 272 | if ($this->dayLinkController) { |
||
| 273 | $linkController = $this->dayLinkController; |
||
| 274 | } |
||
| 275 | $linkCalendar = $currentCalendar; |
||
| 276 | if ($this->dayLinkCalendar) { |
||
| 277 | $linkCalendar = $this->dayLinkCalendar; |
||
| 278 | } |
||
| 279 | $params = $this->dayLinkView->getLinkParams($date); |
||
| 280 | $dateParams['Link'] = $linkCalendar->Link($linkController, $this->dayLinkView, $params); |
||
| 281 | } |
||
| 282 | |||
| 283 | |||
| 284 | |||
| 285 | $this->extend('updateDateParams', $date, $dateParams, $currentCalendar); |
||
| 286 | |||
| 287 | $days[] = new ArrayData($dateParams); |
||
| 288 | } |
||
| 289 | |||
| 290 | $period['Days'] = new ArrayList($days); |
||
| 291 | |||
| 292 | $periods[] = new ArrayData($period); |
||
| 293 | } |
||
| 294 | |||
| 295 | $calendar['Weeks'] = new ArrayList($periods); |
||
| 296 | |||
| 297 | return new ArrayData($calendar); |
||
| 298 | } |
||
| 299 | |||
| 378 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.