We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 16 | 
| Paths | 541 | 
| Total Lines | 115 | 
| Code Lines | 74 | 
| 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  | 
            ||
| 76 | public function calendarAction()  | 
            ||
| 77 |     { | 
            ||
| 78 |         $requestData = GeneralUtility::_GPmerged('tx_dlf'); | 
            ||
| 79 | unset($requestData['__referrer'], $requestData['__trustedProperties']);  | 
            ||
| 80 | |||
| 81 | // access arguments passed by the mainAction()  | 
            ||
| 82 | $mainrquestData = $this->request->getArguments();  | 
            ||
| 83 | |||
| 84 | // merge both arguments together --> passing id by GET parameter tx_dlf[id] should win  | 
            ||
| 85 | $requestData = array_merge($requestData, $mainrquestData);  | 
            ||
| 86 | |||
| 87 | // Load current document.  | 
            ||
| 88 | $this->loadDocument($requestData);  | 
            ||
| 89 |         if ($this->doc === null) { | 
            ||
| 90 | // Quit without doing anything if required variables are not set.  | 
            ||
| 91 | return;  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)  | 
            ||
| 95 |             ->getQueryBuilderForTable('tx_dlf_documents'); | 
            ||
| 96 | |||
| 97 | // Get all children of year anchor.  | 
            ||
| 98 | $result = $queryBuilder  | 
            ||
| 99 | ->select(  | 
            ||
| 100 | 'tx_dlf_documents.uid AS uid',  | 
            ||
| 101 | 'tx_dlf_documents.title AS title',  | 
            ||
| 102 | 'tx_dlf_documents.year AS year',  | 
            ||
| 103 | 'tx_dlf_documents.mets_label AS label',  | 
            ||
| 104 | 'tx_dlf_documents.mets_orderlabel AS orderlabel'  | 
            ||
| 105 | )  | 
            ||
| 106 |             ->from('tx_dlf_documents') | 
            ||
| 107 | ->where(  | 
            ||
| 108 |                 $queryBuilder->expr()->eq('tx_dlf_documents.structure', Helper::getUidFromIndexName('issue', 'tx_dlf_structures', $this->doc->cPid)), | 
            ||
| 109 |                 $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($this->doc->uid)), | 
            ||
| 110 |                 Helper::whereExpression('tx_dlf_documents') | 
            ||
| 111 | )  | 
            ||
| 112 |             ->orderBy('tx_dlf_documents.mets_orderlabel') | 
            ||
| 113 | ->execute();  | 
            ||
| 114 | |||
| 115 | $issues = [];  | 
            ||
| 116 | |||
| 117 | // Process results.  | 
            ||
| 118 |         while ($resArray = $result->fetch()) { | 
            ||
| 119 | // Set title for display in calendar view.  | 
            ||
| 120 |             if (!empty($resArray['title'])) { | 
            ||
| 121 | $title = $resArray['title'];  | 
            ||
| 122 |             } else { | 
            ||
| 123 | $title = !empty($resArray['label']) ? $resArray['label'] : $resArray['orderlabel'];  | 
            ||
| 124 |                 if (strtotime($title) !== false) { | 
            ||
| 125 |                     $title = strftime('%x', strtotime($title)); | 
            ||
| 126 | }  | 
            ||
| 127 | }  | 
            ||
| 128 | $issues[] = [  | 
            ||
| 129 | 'uid' => $resArray['uid'],  | 
            ||
| 130 | 'title' => $title,  | 
            ||
| 131 | 'year' => $resArray['year']  | 
            ||
| 132 | ];  | 
            ||
| 133 | }  | 
            ||
| 134 | // We need an array of issues with year => month => day number as key.  | 
            ||
| 135 | $calendarIssuesByYear = [];  | 
            ||
| 136 |         foreach ($issues as $issue) { | 
            ||
| 137 | $dateTimestamp = strtotime($issue['year']);  | 
            ||
| 138 |             if ($dateTimestamp !== false) { | 
            ||
| 139 |                 $_year = date('Y', $dateTimestamp); | 
            ||
| 140 |                 $_month = date('n', $dateTimestamp); | 
            ||
| 141 |                 $_day = date('j', $dateTimestamp); | 
            ||
| 142 | $calendarIssuesByYear[$_year][$_month][$_day][] = $issue;  | 
            ||
| 143 |             } else { | 
            ||
| 144 |                 $this->logger->warning('Document with UID ' . $issue['uid'] . 'has no valid date of publication'); | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 145 | }  | 
            ||
| 146 | }  | 
            ||
| 147 | // Sort by years.  | 
            ||
| 148 | ksort($calendarIssuesByYear);  | 
            ||
| 149 | // Build calendar for year (default) or season.  | 
            ||
| 150 | $iteration = 1;  | 
            ||
| 151 |         foreach ($calendarIssuesByYear as $year => $calendarIssuesByMonth) { | 
            ||
| 152 | // Sort by months.  | 
            ||
| 153 | ksort($calendarIssuesByMonth);  | 
            ||
| 154 | // Default: First month is January, last month is December.  | 
            ||
| 155 | $firstMonth = 1;  | 
            ||
| 156 | $lastMonth = 12;  | 
            ||
| 157 | // Show calendar from first issue up to end of season if applicable.  | 
            ||
| 158 | if (  | 
            ||
| 159 | empty($this->settings['showEmptyMonths'])  | 
            ||
| 160 | && count($calendarIssuesByYear) > 1  | 
            ||
| 161 |             ) { | 
            ||
| 162 |                 if ($iteration == 1) { | 
            ||
| 163 | $firstMonth = (int) key($calendarIssuesByMonth);  | 
            ||
| 164 |                 } elseif ($iteration == count($calendarIssuesByYear)) { | 
            ||
| 165 | end($calendarIssuesByMonth);  | 
            ||
| 166 | $lastMonth = (int) key($calendarIssuesByMonth);  | 
            ||
| 167 | }  | 
            ||
| 168 | }  | 
            ||
| 169 | $this->getCalendarYear($calendarIssuesByMonth, $year, $firstMonth, $lastMonth);  | 
            ||
| 170 | $iteration++;  | 
            ||
| 171 | }  | 
            ||
| 172 | // Prepare list as alternative view.  | 
            ||
| 173 | $issueData = [];  | 
            ||
| 174 |         foreach ($this->allIssues as $dayTimestamp => $issues) { | 
            ||
| 175 |             $issueData[$dayTimestamp]['dateString'] = strftime('%A, %x', $dayTimestamp); | 
            ||
| 176 | $issueData[$dayTimestamp]['items'] = [];  | 
            ||
| 177 |             foreach ($issues as $issue) { | 
            ||
| 178 | $issueData[$dayTimestamp]['items'][] = $issue;  | 
            ||
| 179 | }  | 
            ||
| 180 | }  | 
            ||
| 181 |         $this->view->assign('issueData', $issueData); | 
            ||
| 182 | |||
| 183 | // Link to current year.  | 
            ||
| 184 | $linkTitleData = $this->doc->getTitledata();  | 
            ||
| 185 | $yearLinkTitle = !empty($linkTitleData['mets_orderlabel'][0]) ? $linkTitleData['mets_orderlabel'][0] : $linkTitleData['mets_label'][0];  | 
            ||
| 186 | |||
| 187 |         $this->view->assign('documentId', $this->doc->uid); | 
            ||
| 188 |         $this->view->assign('yearLinkTitle', $yearLinkTitle); | 
            ||
| 189 |         $this->view->assign('parentDocumentId', $this->doc->parentId); | 
            ||
| 190 |         $this->view->assign('allYearDocTitle', $this->doc->getTitle($this->doc->parentId)); | 
            ||
| 191 | }  | 
            ||
| 388 |