We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 41 |
| Total Lines | 82 |
| Code Lines | 51 |
| 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 |
||
| 145 | public function makeMenuArray() |
||
| 146 | { |
||
| 147 | // Load current document. |
||
| 148 | $this->loadDocument($this->requestData); |
||
| 149 | if ( |
||
| 150 | $this->document === null |
||
| 151 | || $this->document->getDoc() === null |
||
| 152 | ) { |
||
| 153 | // Quit without doing anything if required variables are not set. |
||
| 154 | return []; |
||
| 155 | } else { |
||
| 156 | if (!empty($this->requestData['logicalPage'])) { |
||
| 157 | $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
||
| 158 | // The logical page parameter should not appear again |
||
| 159 | unset($this->requestData['logicalPage']); |
||
| 160 | } |
||
| 161 | // Set default values for page if not set. |
||
| 162 | // $this->piVars['page'] may be integer or string (physical structure @ID) |
||
| 163 | if ( |
||
| 164 | (int) $this->requestData['page'] > 0 |
||
| 165 | || empty($this->requestData['page']) |
||
| 166 | ) { |
||
| 167 | $this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], |
||
| 168 | 1, $this->document->getDoc()->numPages, 1); |
||
| 169 | } else { |
||
| 170 | $this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); |
||
| 171 | } |
||
| 172 | $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], |
||
| 173 | 0, 1, 0); |
||
| 174 | } |
||
| 175 | $menuArray = []; |
||
| 176 | // Does the document have physical elements or is it an external file? |
||
| 177 | if ( |
||
| 178 | !empty($this->document->getDoc()->physicalStructure) |
||
| 179 | || !MathUtility::canBeInterpretedAsInteger($this->document->getDoc()->uid) |
||
|
|
|||
| 180 | ) { |
||
| 181 | // Get all logical units the current page or track is a part of. |
||
| 182 | if ( |
||
| 183 | !empty($this->requestData['page']) |
||
| 184 | && !empty($this->document->getDoc()->physicalStructure) |
||
| 185 | ) { |
||
| 186 | $this->activeEntries = array_merge((array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[0]], |
||
| 187 | (array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]]); |
||
| 188 | if ( |
||
| 189 | !empty($this->requestData['double']) |
||
| 190 | && $this->requestData['page'] < $this->document->getDoc()->numPages |
||
| 191 | ) { |
||
| 192 | $this->activeEntries = array_merge($this->activeEntries, |
||
| 193 | (array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page'] + 1]]); |
||
| 194 | } |
||
| 195 | } |
||
| 196 | // Go through table of contents and create all menu entries. |
||
| 197 | foreach ($this->document->getDoc()->tableOfContents as $entry) { |
||
| 198 | $menuArray[] = $this->getMenuEntry($entry, true); |
||
| 199 | } |
||
| 200 | } else { |
||
| 201 | // Go through table of contents and create top-level menu entries. |
||
| 202 | foreach ($this->document->getDoc()->tableOfContents as $entry) { |
||
| 203 | $menuArray[] = $this->getMenuEntry($entry, false); |
||
| 204 | } |
||
| 205 | // Build table of contents from database. |
||
| 206 | $result = $this->documentRepository->getTableOfContentsFromDb($this->document->getUid(), $this->document->getPid(), $this->settings); |
||
| 207 | |||
| 208 | $allResults = $result->fetchAll(); |
||
| 209 | |||
| 210 | if (count($allResults) > 0) { |
||
| 211 | $menuArray[0]['ITEM_STATE'] = 'CURIFSUB'; |
||
| 212 | $menuArray[0]['_SUB_MENU'] = []; |
||
| 213 | foreach ($allResults as $resArray) { |
||
| 214 | $entry = [ |
||
| 215 | 'label' => !empty($resArray['mets_label']) ? $resArray['mets_label'] : $resArray['title'], |
||
| 216 | 'type' => $resArray['type'], |
||
| 217 | 'volume' => $resArray['volume'], |
||
| 218 | 'orderlabel' => $resArray['mets_orderlabel'], |
||
| 219 | 'pagination' => '', |
||
| 220 | 'targetUid' => $resArray['uid'] |
||
| 221 | ]; |
||
| 222 | $menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, false); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | } |
||
| 226 | return $menuArray; |
||
| 227 | } |
||
| 229 |