We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 28 |
| Paths | 97 |
| Total Lines | 107 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 212 | protected function getCalendarYear($calendarIssuesByMonth, $year, $firstMonth = 1, $lastMonth = 12) |
||
| 213 | { |
||
| 214 | // Get subpart templates. |
||
| 215 | $subPartContent = ''; |
||
| 216 | $subParts['month'] = $this->templateService->getSubpart($this->template, '###CALMONTH###'); |
||
| 217 | $subParts['week'] = $this->templateService->getSubpart($subParts['month'], '###CALWEEK###'); |
||
| 218 | for ($i = $firstMonth; $i <= $lastMonth; $i++) { |
||
| 219 | $markerArray = [ |
||
| 220 | '###DAYMON_NAME###' => strftime('%a', strtotime('last Monday')), |
||
| 221 | '###DAYTUE_NAME###' => strftime('%a', strtotime('last Tuesday')), |
||
| 222 | '###DAYWED_NAME###' => strftime('%a', strtotime('last Wednesday')), |
||
| 223 | '###DAYTHU_NAME###' => strftime('%a', strtotime('last Thursday')), |
||
| 224 | '###DAYFRI_NAME###' => strftime('%a', strtotime('last Friday')), |
||
| 225 | '###DAYSAT_NAME###' => strftime('%a', strtotime('last Saturday')), |
||
| 226 | '###DAYSUN_NAME###' => strftime('%a', strtotime('last Sunday')), |
||
| 227 | '###MONTHNAME###' => strftime('%B', strtotime($year . '-' . $i . '-1')) . ' ' . $year, |
||
| 228 | '###CALYEAR###' => ($i == $firstMonth) ? '<div class="year">' . $year . '</div>' : '' |
||
| 229 | ]; |
||
| 230 | // Fill the month markers. |
||
| 231 | $subPartContentMonth = $this->templateService->substituteMarkerArray($subParts['month'], $markerArray); |
||
| 232 | // Reset week content of new month. |
||
| 233 | $subPartContentWeek = ''; |
||
| 234 | $firstOfMonth = strtotime($year . '-' . $i . '-1'); |
||
| 235 | $lastOfMonth = strtotime('last day of', ($firstOfMonth)); |
||
| 236 | $firstOfMonthStart = strtotime('last Monday', $firstOfMonth); |
||
| 237 | // There are never more than 6 weeks in a month. |
||
| 238 | for ($j = 0; $j <= 5; $j++) { |
||
| 239 | $firstDayOfWeek = strtotime('+ ' . $j . ' Week', $firstOfMonthStart); |
||
| 240 | $weekArray = [ |
||
| 241 | '###DAYMON###' => ' ', |
||
| 242 | '###DAYTUE###' => ' ', |
||
| 243 | '###DAYWED###' => ' ', |
||
| 244 | '###DAYTHU###' => ' ', |
||
| 245 | '###DAYFRI###' => ' ', |
||
| 246 | '###DAYSAT###' => ' ', |
||
| 247 | '###DAYSUN###' => ' ', |
||
| 248 | ]; |
||
| 249 | // Every week has seven days. ;-) |
||
| 250 | for ($k = 0; $k <= 6; $k++) { |
||
| 251 | $currentDayTime = strtotime('+ ' . $k . ' Day', $firstDayOfWeek); |
||
| 252 | if ( |
||
| 253 | $currentDayTime >= $firstOfMonth |
||
| 254 | && $currentDayTime <= $lastOfMonth |
||
| 255 | ) { |
||
| 256 | $dayLinks = ''; |
||
| 257 | $dayLinksText = []; |
||
| 258 | $dayLinksList = ''; |
||
| 259 | $currentMonth = date('n', $currentDayTime); |
||
| 260 | if (is_array($calendarIssuesByMonth[$currentMonth])) { |
||
| 261 | foreach ($calendarIssuesByMonth[$currentMonth] as $id => $day) { |
||
| 262 | if ($id == date('j', $currentDayTime)) { |
||
| 263 | $dayLinks = $id; |
||
| 264 | foreach ($day as $issue) { |
||
| 265 | $dayLinkLabel = empty($issue['title']) ? strftime('%x', $currentDayTime) : $issue['title']; |
||
| 266 | $linkConf = [ |
||
| 267 | 'useCacheHash' => 1, |
||
| 268 | 'parameter' => $this->conf['targetPid'], |
||
| 269 | 'additionalParams' => '&' . $this->prefixId . '[id]=' . urlencode($issue['uid']), |
||
| 270 | 'ATagParams' => ' class="title"', |
||
| 271 | ]; |
||
| 272 | $dayLinksText[] = $this->cObj->typoLink($dayLinkLabel, $linkConf); |
||
| 273 | // Save issue for list view. |
||
| 274 | $this->allIssues[$currentDayTime][] = $this->cObj->typoLink($dayLinkLabel, $linkConf); |
||
| 275 | } |
||
| 276 | } |
||
| 277 | } |
||
| 278 | if (!empty($dayLinksText)) { |
||
| 279 | $dayLinksList = '<ul>'; |
||
| 280 | foreach ($dayLinksText as $link) { |
||
| 281 | $dayLinksList .= '<li>' . $link . '</li>'; |
||
| 282 | } |
||
| 283 | $dayLinksList .= '</ul>'; |
||
| 284 | } |
||
| 285 | $dayLinkDiv = '<div class="issues"><h4>' . strftime('%d', $currentDayTime) . '</h4><div>' . $dayLinksList . '</div></div>'; |
||
| 286 | } |
||
| 287 | switch (strftime('%w', strtotime('+ ' . $k . ' Day', $firstDayOfWeek))) { |
||
| 288 | case '0': |
||
| 289 | $weekArray['###DAYSUN###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
|
|
|||
| 290 | break; |
||
| 291 | case '1': |
||
| 292 | $weekArray['###DAYMON###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 293 | break; |
||
| 294 | case '2': |
||
| 295 | $weekArray['###DAYTUE###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 296 | break; |
||
| 297 | case '3': |
||
| 298 | $weekArray['###DAYWED###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 299 | break; |
||
| 300 | case '4': |
||
| 301 | $weekArray['###DAYTHU###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 302 | break; |
||
| 303 | case '5': |
||
| 304 | $weekArray['###DAYFRI###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 305 | break; |
||
| 306 | case '6': |
||
| 307 | $weekArray['###DAYSAT###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 308 | break; |
||
| 309 | } |
||
| 310 | } |
||
| 311 | } |
||
| 312 | // Fill the weeks. |
||
| 313 | $subPartContentWeek .= $this->templateService->substituteMarkerArray($subParts['week'], $weekArray); |
||
| 314 | } |
||
| 315 | // Fill the week markers with the week entries. |
||
| 316 | $subPartContent .= $this->templateService->substituteSubpart($subPartContentMonth, '###CALWEEK###', $subPartContentWeek); |
||
| 317 | } |
||
| 318 | return $subPartContent; |
||
| 319 | } |
||
| 407 |