We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 26 | 
| Paths | 67 | 
| Total Lines | 113 | 
| Code Lines | 83 | 
| 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 | ||
| 273 | protected function getCalendarYear($calendarIssuesByMonth, $year, $firstMonth = 1, $lastMonth = 12) | ||
| 274 |     { | ||
| 275 | $calendarData = []; | ||
| 276 |         for ($i = $firstMonth; $i <= $lastMonth; $i++) { | ||
| 277 | $calendarData[$i] = [ | ||
| 278 |                 'DAYMON_NAME' => strftime('%a', strtotime('last Monday')), | ||
| 279 |                 'DAYTUE_NAME' => strftime('%a', strtotime('last Tuesday')), | ||
| 280 |                 'DAYWED_NAME' => strftime('%a', strtotime('last Wednesday')), | ||
| 281 |                 'DAYTHU_NAME' => strftime('%a', strtotime('last Thursday')), | ||
| 282 |                 'DAYFRI_NAME' => strftime('%a', strtotime('last Friday')), | ||
| 283 |                 'DAYSAT_NAME' => strftime('%a', strtotime('last Saturday')), | ||
| 284 |                 'DAYSUN_NAME' => strftime('%a', strtotime('last Sunday')), | ||
| 285 |                 'MONTHNAME'  => strftime('%B', strtotime($year . '-' . $i . '-1')) . ' ' . $year, | ||
| 286 | 'CALYEAR' => ($i == $firstMonth) ? $year : '' | ||
| 287 | ]; | ||
| 288 | |||
| 289 | $firstOfMonth = strtotime($year . '-' . $i . '-1'); | ||
| 290 |             $lastOfMonth = strtotime('last day of', ($firstOfMonth)); | ||
| 291 |             $firstOfMonthStart = strtotime('last Monday', $firstOfMonth); | ||
| 292 | // There are never more than 6 weeks in a month. | ||
| 293 |             for ($j = 0; $j <= 5; $j++) { | ||
| 294 |                 $firstDayOfWeek = strtotime('+ ' . $j . ' Week', $firstOfMonthStart); | ||
| 295 | |||
| 296 | $calendarData[$i]['week'][$j] = [ | ||
| 297 | 'DAYMON' => ['dayValue' => ' '], | ||
| 298 | 'DAYTUE' => ['dayValue' => ' '], | ||
| 299 | 'DAYWED' => ['dayValue' => ' '], | ||
| 300 | 'DAYTHU' => ['dayValue' => ' '], | ||
| 301 | 'DAYFRI' => ['dayValue' => ' '], | ||
| 302 | 'DAYSAT' => ['dayValue' => ' '], | ||
| 303 | 'DAYSUN' => ['dayValue' => ' '], | ||
| 304 | ]; | ||
| 305 | // Every week has seven days. ;-) | ||
| 306 |                 for ($k = 0; $k <= 6; $k++) { | ||
| 307 |                     $currentDayTime = strtotime('+ ' . $k . ' Day', $firstDayOfWeek); | ||
| 308 | if ( | ||
| 309 | $currentDayTime >= $firstOfMonth | ||
| 310 | && $currentDayTime <= $lastOfMonth | ||
| 311 |                     ) { | ||
| 312 | $dayLinks = ''; | ||
| 313 | $dayLinksText = []; | ||
| 314 |                         $currentMonth = date('n', $currentDayTime); | ||
| 315 |                         if (is_array($calendarIssuesByMonth[$currentMonth])) { | ||
| 316 |                             foreach ($calendarIssuesByMonth[$currentMonth] as $id => $day) { | ||
| 317 |                                 if ($id == date('j', $currentDayTime)) { | ||
| 318 | $dayLinks = $id; | ||
| 319 |                                     foreach ($day as $issue) { | ||
| 320 |                                         $dayLinkLabel = empty($issue['title']) ? strftime('%x', $currentDayTime) : $issue['title']; | ||
| 321 | |||
| 322 | $dayLinksText[] = [ | ||
| 323 | 'documentId' => $issue['uid'], | ||
| 324 | 'text' => $dayLinkLabel | ||
| 325 | ]; | ||
| 326 | |||
| 327 | // Save issue for list view. | ||
| 328 | $this->allIssues[$currentDayTime][] = [ | ||
| 329 | 'documentId' => $issue['uid'], | ||
| 330 | 'text' => $dayLinkLabel | ||
| 331 | ]; | ||
| 332 | } | ||
| 333 | } | ||
| 334 | } | ||
| 335 | $dayLinkDiv = $dayLinksText; | ||
| 336 | } | ||
| 337 |                         switch (strftime('%w', strtotime('+ ' . $k . ' Day', $firstDayOfWeek))) { | ||
| 338 | case '0': | ||
| 339 |                                 $calendarData[$i]['week'][$j]['DAYSUN']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 340 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 341 | $calendarData[$i]['week'][$j]['DAYSUN']['issues'] = $dayLinkDiv; | ||
| 342 | } | ||
| 343 | break; | ||
| 344 | case '1': | ||
| 345 |                                 $calendarData[$i]['week'][$j]['DAYMON']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 346 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 347 | $calendarData[$i]['week'][$j]['DAYMON']['issues'] = $dayLinkDiv; | ||
| 348 | } | ||
| 349 | break; | ||
| 350 | case '2': | ||
| 351 |                                 $calendarData[$i]['week'][$j]['DAYTUE']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 352 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 353 | $calendarData[$i]['week'][$j]['DAYTUE']['issues'] = $dayLinkDiv; | ||
| 354 | } | ||
| 355 | break; | ||
| 356 | case '3': | ||
| 357 |                                 $calendarData[$i]['week'][$j]['DAYWED']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 358 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 359 | $calendarData[$i]['week'][$j]['DAYWED']['issues'] = $dayLinkDiv; | ||
| 360 | } | ||
| 361 | break; | ||
| 362 | case '4': | ||
| 363 |                                 $calendarData[$i]['week'][$j]['DAYTHU']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 364 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 365 | $calendarData[$i]['week'][$j]['DAYTHU']['issues'] = $dayLinkDiv; | ||
| 366 | } | ||
| 367 | break; | ||
| 368 | case '5': | ||
| 369 |                                 $calendarData[$i]['week'][$j]['DAYFRI']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 370 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 371 | $calendarData[$i]['week'][$j]['DAYFRI']['issues'] = $dayLinkDiv; | ||
| 372 | } | ||
| 373 | break; | ||
| 374 | case '6': | ||
| 375 |                                 $calendarData[$i]['week'][$j]['DAYSAT']['dayValue'] = strftime('%d', $currentDayTime); | ||
| 376 |                                 if ((int) $dayLinks === (int) date('j', $currentDayTime)) { | ||
| 377 | $calendarData[$i]['week'][$j]['DAYSAT']['issues'] = $dayLinkDiv; | ||
| 378 | } | ||
| 379 | break; | ||
| 380 | } | ||
| 381 | } | ||
| 382 | } | ||
| 383 | } | ||
| 384 | } | ||
| 385 |         $this->view->assign('calendarData', $calendarData); | ||
| 386 | } | ||
| 388 |