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