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