We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 57 |
| Total Lines | 113 |
| Code Lines | 76 |
| 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 |
||
| 180 | public function makeMenuArray($requestData) |
||
| 181 | { |
||
| 182 | // Load current document. |
||
| 183 | $this->loadDocument($requestData); |
||
| 184 | if ($this->doc === null) { |
||
| 185 | // Quit without doing anything if required variables are not set. |
||
| 186 | return []; |
||
| 187 | } else { |
||
| 188 | if (!empty($requestData['logicalPage'])) { |
||
| 189 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 190 | // The logical page parameter should not appear again |
||
| 191 | unset($requestData['logicalPage']); |
||
| 192 | } |
||
| 193 | // Set default values for page if not set. |
||
| 194 | // $this->piVars['page'] may be integer or string (physical structure @ID) |
||
| 195 | if ( |
||
| 196 | (int)$requestData['page'] > 0 |
||
| 197 | || empty($requestData['page']) |
||
| 198 | ) { |
||
| 199 | $requestData['page'] = MathUtility::forceIntegerInRange((int)$requestData['page'], |
||
| 200 | 1, $this->doc->numPages, 1); |
||
| 201 | } else { |
||
| 202 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 203 | } |
||
| 204 | $requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], |
||
| 205 | 0, 1, 0); |
||
| 206 | } |
||
| 207 | $menuArray = []; |
||
| 208 | // Does the document have physical elements or is it an external file? |
||
| 209 | if ( |
||
| 210 | !empty($this->doc->physicalStructure) |
||
| 211 | || !MathUtility::canBeInterpretedAsInteger($this->doc->uid) |
||
| 212 | ) { |
||
| 213 | // Get all logical units the current page or track is a part of. |
||
| 214 | if ( |
||
| 215 | !empty($requestData['page']) |
||
| 216 | && !empty($this->doc->physicalStructure) |
||
| 217 | ) { |
||
| 218 | $this->activeEntries = array_merge((array)$this->doc->smLinks['p2l'][$this->doc->physicalStructure[0]], |
||
| 219 | (array)$this->doc->smLinks['p2l'][$this->doc->physicalStructure[$requestData['page']]]); |
||
| 220 | if ( |
||
| 221 | !empty($requestData['double']) |
||
| 222 | && $requestData['page'] < $this->doc->numPages |
||
| 223 | ) { |
||
| 224 | $this->activeEntries = array_merge($this->activeEntries, |
||
| 225 | (array)$this->doc->smLinks['p2l'][$this->doc->physicalStructure[$requestData['page'] + 1]]); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | // Go through table of contents and create all menu entries. |
||
| 229 | foreach ($this->doc->tableOfContents as $entry) { |
||
| 230 | $menuArray[] = $this->getMenuEntry($entry, true); |
||
| 231 | } |
||
| 232 | } else { |
||
| 233 | // Go through table of contents and create top-level menu entries. |
||
| 234 | foreach ($this->doc->tableOfContents as $entry) { |
||
| 235 | $menuArray[] = $this->getMenuEntry($entry, false); |
||
| 236 | } |
||
| 237 | // Build table of contents from database. |
||
| 238 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 239 | ->getQueryBuilderForTable('tx_dlf_documents'); |
||
| 240 | |||
| 241 | $excludeOtherWhere = ''; |
||
| 242 | if ($this->settings['excludeOther']) { |
||
| 243 | $excludeOtherWhere = 'tx_dlf_documents.pid=' . intval($this->settings['pages']); |
||
| 244 | } |
||
| 245 | // Check if there are any metadata to suggest. |
||
| 246 | $result = $queryBuilder |
||
| 247 | ->select( |
||
| 248 | 'tx_dlf_documents.uid AS uid', |
||
| 249 | 'tx_dlf_documents.title AS title', |
||
| 250 | 'tx_dlf_documents.volume AS volume', |
||
| 251 | 'tx_dlf_documents.mets_label AS mets_label', |
||
| 252 | 'tx_dlf_documents.mets_orderlabel AS mets_orderlabel', |
||
| 253 | 'tx_dlf_structures_join.index_name AS type' |
||
| 254 | ) |
||
| 255 | ->innerJoin( |
||
| 256 | 'tx_dlf_documents', |
||
| 257 | 'tx_dlf_structures', |
||
| 258 | 'tx_dlf_structures_join', |
||
| 259 | $queryBuilder->expr()->eq( |
||
| 260 | 'tx_dlf_structures_join.uid', |
||
| 261 | 'tx_dlf_documents.structure' |
||
| 262 | ) |
||
| 263 | ) |
||
| 264 | ->from('tx_dlf_documents') |
||
| 265 | ->where( |
||
| 266 | $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($this->doc->uid)), |
||
| 267 | $queryBuilder->expr()->eq('tx_dlf_structures_join.pid', intval($this->doc->pid)), |
||
| 268 | $excludeOtherWhere |
||
| 269 | ) |
||
| 270 | ->addOrderBy('tx_dlf_documents.volume_sorting') |
||
| 271 | ->addOrderBy('tx_dlf_documents.mets_orderlabel') |
||
| 272 | ->execute(); |
||
| 273 | |||
| 274 | $allResults = $result->fetchAll(); |
||
| 275 | |||
| 276 | if (count($allResults) > 0) { |
||
| 277 | $menuArray[0]['ITEM_STATE'] = 'CURIFSUB'; |
||
| 278 | $menuArray[0]['_SUB_MENU'] = []; |
||
| 279 | foreach ($allResults as $resArray) { |
||
| 280 | $entry = [ |
||
| 281 | 'label' => !empty($resArray['mets_label']) ? $resArray['mets_label'] : $resArray['title'], |
||
| 282 | 'type' => $resArray['type'], |
||
| 283 | 'volume' => $resArray['volume'], |
||
| 284 | 'orderlabel' => $resArray['mets_orderlabel'], |
||
| 285 | 'pagination' => '', |
||
| 286 | 'targetUid' => $resArray['uid'] |
||
| 287 | ]; |
||
| 288 | $menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, false); |
||
| 289 | } |
||
| 290 | } |
||
| 291 | } |
||
| 292 | return $menuArray; |
||
| 293 | } |
||
| 295 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.