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 | 114 |
| Code Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 248 | protected function getCalendarYear($calendarIssuesByMonth, $year, $firstMonth = 1, $lastMonth = 12) |
||
| 249 | { |
||
| 250 | $calendarData = []; |
||
| 251 | for ($i = $firstMonth; $i <= $lastMonth; $i++) { |
||
| 252 | $calendarData[$i] = [ |
||
| 253 | 'DAYMON_NAME' => strftime('%a', strtotime('last Monday')), |
||
| 254 | 'DAYTUE_NAME' => strftime('%a', strtotime('last Tuesday')), |
||
| 255 | 'DAYWED_NAME' => strftime('%a', strtotime('last Wednesday')), |
||
| 256 | 'DAYTHU_NAME' => strftime('%a', strtotime('last Thursday')), |
||
| 257 | 'DAYFRI_NAME' => strftime('%a', strtotime('last Friday')), |
||
| 258 | 'DAYSAT_NAME' => strftime('%a', strtotime('last Saturday')), |
||
| 259 | 'DAYSUN_NAME' => strftime('%a', strtotime('last Sunday')), |
||
| 260 | 'MONTHNAME' => strftime('%B', strtotime($year . '-' . $i . '-1')) . ' ' . $year, |
||
| 261 | 'CALYEAR' => ($i == $firstMonth) ? $year : '' |
||
| 262 | ]; |
||
| 263 | |||
| 264 | $firstOfMonth = strtotime($year . '-' . $i . '-1'); |
||
| 265 | $lastOfMonth = strtotime('last day of', ($firstOfMonth)); |
||
| 266 | $firstOfMonthStart = strtotime('last Monday', $firstOfMonth); |
||
| 267 | // There are never more than 6 weeks in a month. |
||
| 268 | for ($j = 0; $j <= 5; $j++) { |
||
| 269 | $firstDayOfWeek = strtotime('+ ' . $j . ' Week', $firstOfMonthStart); |
||
| 270 | |||
| 271 | $calendarData[$i]['week'][$j] = [ |
||
| 272 | 'DAYMON' => ['dayValue' => ' '], |
||
| 273 | 'DAYTUE' => ['dayValue' => ' '], |
||
| 274 | 'DAYWED' => ['dayValue' => ' '], |
||
| 275 | 'DAYTHU' => ['dayValue' => ' '], |
||
| 276 | 'DAYFRI' => ['dayValue' => ' '], |
||
| 277 | 'DAYSAT' => ['dayValue' => ' '], |
||
| 278 | 'DAYSUN' => ['dayValue' => ' '], |
||
| 279 | ]; |
||
| 280 | // Every week has seven days. ;-) |
||
| 281 | for ($k = 0; $k <= 6; $k++) { |
||
| 282 | $currentDayTime = strtotime('+ ' . $k . ' Day', $firstDayOfWeek); |
||
| 283 | if ( |
||
| 284 | $currentDayTime >= $firstOfMonth |
||
| 285 | && $currentDayTime <= $lastOfMonth |
||
| 286 | ) { |
||
| 287 | $dayLinks = ''; |
||
| 288 | $dayLinksText = []; |
||
| 289 | $dayLinkDiv = []; |
||
| 290 | $currentMonth = date('n', $currentDayTime); |
||
| 291 | if (is_array($calendarIssuesByMonth[$currentMonth])) { |
||
| 292 | foreach ($calendarIssuesByMonth[$currentMonth] as $id => $day) { |
||
| 293 | if ($id == date('j', $currentDayTime)) { |
||
| 294 | $dayLinks = $id; |
||
| 295 | foreach ($day as $issue) { |
||
| 296 | $dayLinkLabel = empty($issue['title']) ? strftime('%x', $currentDayTime) : $issue['title']; |
||
| 297 | |||
| 298 | $dayLinksText[] = [ |
||
| 299 | 'documentId' => $issue['uid'], |
||
| 300 | 'text' => $dayLinkLabel |
||
| 301 | ]; |
||
| 302 | |||
| 303 | // Save issue for list view. |
||
| 304 | $this->allIssues[$currentDayTime][] = [ |
||
| 305 | 'documentId' => $issue['uid'], |
||
| 306 | 'text' => $dayLinkLabel |
||
| 307 | ]; |
||
| 308 | } |
||
| 309 | } |
||
| 310 | } |
||
| 311 | $dayLinkDiv = $dayLinksText; |
||
| 312 | } |
||
| 313 | switch (strftime('%w', strtotime('+ ' . $k . ' Day', $firstDayOfWeek))) { |
||
| 314 | case '0': |
||
| 315 | $calendarData[$i]['week'][$j]['DAYSUN']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 316 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 317 | $calendarData[$i]['week'][$j]['DAYSUN']['issues'] = $dayLinkDiv; |
||
| 318 | } |
||
| 319 | break; |
||
| 320 | case '1': |
||
| 321 | $calendarData[$i]['week'][$j]['DAYMON']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 322 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 323 | $calendarData[$i]['week'][$j]['DAYMON']['issues'] = $dayLinkDiv; |
||
| 324 | } |
||
| 325 | break; |
||
| 326 | case '2': |
||
| 327 | $calendarData[$i]['week'][$j]['DAYTUE']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 328 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 329 | $calendarData[$i]['week'][$j]['DAYTUE']['issues'] = $dayLinkDiv; |
||
| 330 | } |
||
| 331 | break; |
||
| 332 | case '3': |
||
| 333 | $calendarData[$i]['week'][$j]['DAYWED']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 334 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 335 | $calendarData[$i]['week'][$j]['DAYWED']['issues'] = $dayLinkDiv; |
||
| 336 | } |
||
| 337 | break; |
||
| 338 | case '4': |
||
| 339 | $calendarData[$i]['week'][$j]['DAYTHU']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 340 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 341 | $calendarData[$i]['week'][$j]['DAYTHU']['issues'] = $dayLinkDiv; |
||
| 342 | } |
||
| 343 | break; |
||
| 344 | case '5': |
||
| 345 | $calendarData[$i]['week'][$j]['DAYFRI']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 346 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 347 | $calendarData[$i]['week'][$j]['DAYFRI']['issues'] = $dayLinkDiv; |
||
| 348 | } |
||
| 349 | break; |
||
| 350 | case '6': |
||
| 351 | $calendarData[$i]['week'][$j]['DAYSAT']['dayValue'] = strftime('%d', $currentDayTime); |
||
| 352 | if ((int) $dayLinks === (int) date('j', $currentDayTime)) { |
||
| 353 | $calendarData[$i]['week'][$j]['DAYSAT']['issues'] = $dayLinkDiv; |
||
| 354 | } |
||
| 355 | break; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | } |
||
| 360 | } |
||
| 361 | $this->view->assign('calendarData', $calendarData); |
||
| 362 | } |
||
| 364 |