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