We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 22 |
| Paths | 4377 |
| Total Lines | 145 |
| Code Lines | 105 |
| 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 |
||
| 253 | protected function showSingleCollection($id) { |
||
| 254 | /** @var QueryBuilder $queryBuilder */ |
||
| 255 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 256 | ->getQueryBuilderForTable('tx_dlf_collections'); |
||
| 257 | |||
| 258 | $additionalWhere = ''; |
||
| 259 | // Should user-defined collections be shown? |
||
| 260 | if (empty($this->conf['show_userdefined'])) { |
||
| 261 | $additionalWhere = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 262 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
| 263 | $additionalWhere = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 264 | } |
||
| 265 | |||
| 266 | // Get collection information from DB |
||
| 267 | $collection = $queryBuilder |
||
| 268 | ->select( |
||
| 269 | 'tx_dlf_collections.index_name AS index_name', |
||
| 270 | 'tx_dlf_collections.index_search as index_search', |
||
| 271 | 'tx_dlf_collections.label AS collLabel', |
||
| 272 | 'tx_dlf_collections.description AS collDesc', |
||
| 273 | 'tx_dlf_collections.thumbnail AS collThumb', |
||
| 274 | 'tx_dlf_collections.fe_cruser_id' |
||
| 275 | ) |
||
| 276 | ->from('tx_dlf_collections') |
||
| 277 | ->where( |
||
| 278 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->conf['pages'])), |
||
| 279 | $queryBuilder->expr()->eq('tx_dlf_collections.uid', intval($id)), |
||
| 280 | $additionalWhere, |
||
| 281 | $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0), |
||
| 282 | Helper::whereExpression('tx_dlf_collections') |
||
| 283 | ) |
||
| 284 | ->setMaxResults(1) |
||
| 285 | ->execute(); |
||
| 286 | |||
| 287 | // Fetch corresponding document UIDs from Solr. |
||
| 288 | if ($resArray = $collection->fetch()) { |
||
| 289 | $collectionData = $resArray; |
||
| 290 | } else { |
||
| 291 | Helper::devLog('No collection with UID '.$id.' found.', DEVLOG_SEVERITY_WARNING); |
||
| 292 | return; |
||
| 293 | } |
||
| 294 | if ($collectionData['index_search'] != '') { |
||
| 295 | $solr_query = '('.$collectionData['index_search'].')'; |
||
| 296 | } else { |
||
| 297 | $solr_query = 'collection:("'.$collectionData['index_name'].'")'; |
||
| 298 | } |
||
| 299 | $solr = Solr::getInstance($this->conf['solrcore']); |
||
| 300 | if (!$solr->ready) { |
||
| 301 | Helper::devLog('Apache Solr not available', DEVLOG_SEVERITY_ERROR); |
||
| 302 | return; |
||
| 303 | } |
||
| 304 | $params['fields'] = 'uid'; |
||
|
1 ignored issue
–
show
|
|||
| 305 | $params['sort'] = ['uid' => 'asc']; |
||
| 306 | $solrResult = $solr->search_raw($solr_query, $params); |
||
| 307 | // Initialize array |
||
| 308 | $documentSet = []; |
||
| 309 | foreach ($solrResult as $doc) { |
||
| 310 | $documentSet[] = $doc->uid; |
||
| 311 | } |
||
| 312 | $documentSet = array_unique($documentSet); |
||
| 313 | // Fetch document info for UIDs in $documentSet from DB |
||
| 314 | $documents = $queryBuilder |
||
| 315 | ->select( |
||
| 316 | 'tx_dlf_documents.uid AS uid', |
||
| 317 | 'tx_dlf_documents.metadata_sorting AS metadata_sorting', |
||
| 318 | 'tx_dlf_documents.volume_sorting AS volume_sorting', |
||
| 319 | 'tx_dlf_documents.partof AS partof' |
||
| 320 | ) |
||
| 321 | ->from('tx_dlf_documents') |
||
| 322 | ->where( |
||
| 323 | $queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($this->conf['pages'])), |
||
| 324 | $queryBuilder->expr()->in('tx_dlf_documents.uid', $documentSet), |
||
| 325 | Helper::whereExpression('tx_dlf_documents') |
||
| 326 | ) |
||
| 327 | ->execute(); |
||
| 328 | |||
| 329 | $toplevel = []; |
||
| 330 | $subparts = []; |
||
| 331 | $listMetadata = []; |
||
| 332 | // Process results. |
||
| 333 | while ($resArray = $documents->fetch()) { |
||
| 334 | if (empty($l10nOverlay)) { |
||
| 335 | $l10nOverlay = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_collections', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 336 | } |
||
| 337 | if (empty($listMetadata)) { |
||
| 338 | $listMetadata = [ |
||
| 339 | 'label' => !empty($l10nOverlay['label']) ? htmlspecialchars($l10nOverlay['label']) : htmlspecialchars($collectionData['collLabel']), |
||
| 340 | 'description' => !empty($l10nOverlay['description']) ? $this->pi_RTEcssText($l10nOverlay['description']) : $this->pi_RTEcssText($collectionData['collDesc']), |
||
| 341 | 'thumbnail' => htmlspecialchars($collectionData['collThumb']), |
||
| 342 | 'options' => [ |
||
| 343 | 'source' => 'collection', |
||
| 344 | 'select' => $id, |
||
| 345 | 'userid' => $collectionData['userid'], |
||
| 346 | 'params' => ['filterquery' => [['query' => 'collection_faceting:("'.$collectionData['index_name'].'")']]], |
||
| 347 | 'core' => '', |
||
| 348 | 'pid' => $this->conf['pages'], |
||
| 349 | 'order' => 'title', |
||
| 350 | 'order.asc' => TRUE |
||
| 351 | ] |
||
| 352 | ]; |
||
| 353 | } |
||
| 354 | // Split toplevel documents from volumes. |
||
| 355 | if ($resArray['partof'] == 0) { |
||
| 356 | // Prepare document's metadata for sorting. |
||
| 357 | $sorting = unserialize($resArray['metadata_sorting']); |
||
| 358 | if (!empty($sorting['type']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['type'])) { |
||
| 359 | $sorting['type'] = Helper::getIndexNameFromUid($sorting['type'], 'tx_dlf_structures', $this->conf['pages']); |
||
| 360 | } |
||
| 361 | if (!empty($sorting['owner']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['owner'])) { |
||
| 362 | $sorting['owner'] = Helper::getIndexNameFromUid($sorting['owner'], 'tx_dlf_libraries', $this->conf['pages']); |
||
| 363 | } |
||
| 364 | if (!empty($sorting['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['collection'])) { |
||
| 365 | $sorting['collection'] = Helper::getIndexNameFromUid($sorting['collection'], 'tx_dlf_collections', $this->conf['pages']); |
||
| 366 | } |
||
| 367 | $toplevel[$resArray['uid']] = [ |
||
| 368 | 'u' => $resArray['uid'], |
||
| 369 | 'h' => '', |
||
| 370 | 's' => $sorting, |
||
| 371 | 'p' => [] |
||
| 372 | ]; |
||
| 373 | } else { |
||
| 374 | $subparts[$resArray['partof']][$resArray['volume_sorting']] = $resArray['uid']; |
||
| 375 | } |
||
| 376 | } |
||
| 377 | // Add volumes to the corresponding toplevel documents. |
||
| 378 | foreach ($subparts as $partof => $parts) { |
||
| 379 | if (!empty($toplevel[$partof])) { |
||
| 380 | ksort($parts); |
||
| 381 | foreach ($parts as $part) { |
||
| 382 | $toplevel[$partof]['p'][] = ['u' => $part]; |
||
| 383 | } |
||
| 384 | } |
||
| 385 | } |
||
| 386 | // Save list of documents. |
||
| 387 | $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(DocumentList::class); |
||
| 388 | $list->reset(); |
||
| 389 | $list->add(array_values($toplevel)); |
||
| 390 | $listMetadata['options']['numberOfToplevelHits'] = count($list); |
||
| 391 | $list->metadata = $listMetadata; |
||
| 392 | $list->save(); |
||
| 393 | // Clean output buffer. |
||
| 394 | ob_end_clean(); |
||
| 395 | // Send headers. |
||
| 396 | header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL(['parameter' => $this->conf['targetPid']]))); |
||
| 397 | exit; |
||
| 398 | } |
||
| 400 |