We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 21 |
| Paths | 4767 |
| Total Lines | 168 |
| Code Lines | 123 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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 |
||
| 260 | protected function showSingleCollection($id) |
||
| 261 | { |
||
| 262 | $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
||
| 263 | $queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_collections'); |
||
| 264 | |||
| 265 | $additionalWhere = ''; |
||
| 266 | // Should user-defined collections be shown? |
||
| 267 | if (empty($this->conf['show_userdefined'])) { |
||
| 268 | $additionalWhere = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 269 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
| 270 | $additionalWhere = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 271 | } |
||
| 272 | |||
| 273 | // Get collection information from DB |
||
| 274 | $collection = $queryBuilder |
||
| 275 | ->select( |
||
| 276 | 'tx_dlf_collections.uid AS uid', // required by getRecordOverlay() |
||
| 277 | 'tx_dlf_collections.pid AS pid', // required by getRecordOverlay() |
||
| 278 | 'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay() |
||
| 279 | 'tx_dlf_collections.index_name AS index_name', |
||
| 280 | 'tx_dlf_collections.index_search as index_search', |
||
| 281 | 'tx_dlf_collections.label AS label', |
||
| 282 | 'tx_dlf_collections.description AS description', |
||
| 283 | 'tx_dlf_collections.thumbnail AS thumbnail', |
||
| 284 | 'tx_dlf_collections.fe_cruser_id' |
||
| 285 | ) |
||
| 286 | ->from('tx_dlf_collections') |
||
| 287 | ->where( |
||
| 288 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->conf['pages'])), |
||
| 289 | $queryBuilder->expr()->eq('tx_dlf_collections.uid', intval($id)), |
||
| 290 | $additionalWhere, |
||
| 291 | $queryBuilder->expr()->andX( |
||
| 292 | $queryBuilder->expr()->orX( |
||
| 293 | $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]), |
||
| 294 | $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $GLOBALS['TSFE']->sys_language_uid) |
||
| 295 | ), |
||
| 296 | $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0) |
||
| 297 | ), |
||
| 298 | Helper::whereExpression('tx_dlf_collections') |
||
| 299 | ) |
||
| 300 | ->setMaxResults(1) |
||
| 301 | ->execute(); |
||
| 302 | |||
| 303 | // Get language overlay if on alterative website language. |
||
| 304 | $pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class); |
||
| 305 | if ($resArray = $collection->fetch()) { |
||
| 306 | if ($resArray['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content) { |
||
| 307 | $collectionData = $pageRepository->getRecordOverlay('tx_dlf_collections', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 308 | } else { |
||
| 309 | $collectionData = $resArray; |
||
| 310 | } |
||
| 311 | } else { |
||
| 312 | Helper::devLog('No collection with UID ' . $id . ' found.', DEVLOG_SEVERITY_WARNING); |
||
| 313 | return; |
||
| 314 | } |
||
| 315 | // Fetch corresponding document UIDs from Solr. |
||
| 316 | if ($collectionData['index_search'] != '') { |
||
| 317 | $solr_query = '(' . $collectionData['index_search'] . ')'; |
||
| 318 | } else { |
||
| 319 | $solr_query = 'collection:("' . $collectionData['index_name'] . '") AND toplevel:true'; |
||
| 320 | } |
||
| 321 | $solr = Solr::getInstance($this->conf['solrcore']); |
||
| 322 | if (!$solr->ready) { |
||
| 323 | Helper::devLog('Apache Solr not available', DEVLOG_SEVERITY_ERROR); |
||
| 324 | return; |
||
| 325 | } |
||
| 326 | $params['fields'] = 'uid'; |
||
| 327 | $params['sort'] = ['uid' => 'asc']; |
||
| 328 | $solrResult = $solr->search_raw($solr_query, $params); |
||
| 329 | // Initialize array |
||
| 330 | $documentSet = []; |
||
| 331 | foreach ($solrResult as $doc) { |
||
| 332 | if ($doc->uid) { |
||
| 333 | $documentSet[] = $doc->uid; |
||
| 334 | } |
||
| 335 | } |
||
| 336 | $documentSet = array_unique($documentSet); |
||
| 337 | $queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_documents'); |
||
| 338 | // Fetch document info for UIDs in $documentSet from DB |
||
| 339 | $documents = $queryBuilder |
||
| 340 | ->select( |
||
| 341 | 'tx_dlf_documents.uid AS uid', |
||
| 342 | 'tx_dlf_documents.metadata_sorting AS metadata_sorting', |
||
| 343 | 'tx_dlf_documents.volume_sorting AS volume_sorting', |
||
| 344 | 'tx_dlf_documents.partof AS partof' |
||
| 345 | ) |
||
| 346 | ->from('tx_dlf_documents') |
||
| 347 | ->where( |
||
| 348 | $queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($this->conf['pages'])), |
||
| 349 | $queryBuilder->expr()->in('tx_dlf_documents.uid', $documentSet), |
||
| 350 | Helper::whereExpression('tx_dlf_documents') |
||
| 351 | ) |
||
| 352 | ->execute(); |
||
| 353 | |||
| 354 | $toplevel = []; |
||
| 355 | $subparts = []; |
||
| 356 | $listMetadata = []; |
||
| 357 | // Process results. |
||
| 358 | while ($resArray = $documents->fetch()) { |
||
| 359 | if (empty($listMetadata)) { |
||
| 360 | $listMetadata = [ |
||
| 361 | 'label' => htmlspecialchars($collectionData['label']), |
||
| 362 | 'description' => $this->pi_RTEcssText($collectionData['description']), |
||
| 363 | 'thumbnail' => htmlspecialchars($collectionData['thumbnail']), |
||
| 364 | 'options' => [ |
||
| 365 | 'source' => 'collection', |
||
| 366 | 'select' => $id, |
||
| 367 | 'userid' => $collectionData['userid'], |
||
| 368 | 'params' => ['filterquery' => [['query' => 'collection_faceting:("' . $collectionData['index_name'] . '")']]], |
||
| 369 | 'core' => '', |
||
| 370 | 'pid' => $this->conf['pages'], |
||
| 371 | 'order' => 'title', |
||
| 372 | 'order.asc' => true |
||
| 373 | ] |
||
| 374 | ]; |
||
| 375 | } |
||
| 376 | // Prepare document's metadata for sorting. |
||
| 377 | $sorting = unserialize($resArray['metadata_sorting']); |
||
| 378 | if (!empty($sorting['type']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['type'])) { |
||
| 379 | $sorting['type'] = Helper::getIndexNameFromUid($sorting['type'], 'tx_dlf_structures', $this->conf['pages']); |
||
| 380 | } |
||
| 381 | if (!empty($sorting['owner']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['owner'])) { |
||
| 382 | $sorting['owner'] = Helper::getIndexNameFromUid($sorting['owner'], 'tx_dlf_libraries', $this->conf['pages']); |
||
| 383 | } |
||
| 384 | if (!empty($sorting['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['collection'])) { |
||
| 385 | $sorting['collection'] = Helper::getIndexNameFromUid($sorting['collection'], 'tx_dlf_collections', $this->conf['pages']); |
||
| 386 | } |
||
| 387 | // Split toplevel documents from volumes. |
||
| 388 | if ($resArray['partof'] == 0) { |
||
| 389 | $toplevel[$resArray['uid']] = [ |
||
| 390 | 'u' => $resArray['uid'], |
||
| 391 | 'h' => '', |
||
| 392 | 's' => $sorting, |
||
| 393 | 'p' => [] |
||
| 394 | ]; |
||
| 395 | } else { |
||
| 396 | $subparts[$resArray['partof']][$resArray['volume_sorting']] = [ |
||
| 397 | 'u' => $resArray['uid'], |
||
| 398 | 'h' => '', |
||
| 399 | 's' => $sorting, |
||
| 400 | 'p' => [] |
||
| 401 | ]; |
||
| 402 | } |
||
| 403 | } |
||
| 404 | // Add volumes to the corresponding toplevel documents. |
||
| 405 | foreach ($subparts as $partof => $parts) { |
||
| 406 | ksort($parts); |
||
| 407 | foreach ($parts as $part) { |
||
| 408 | if (!empty($toplevel[$partof])) { |
||
| 409 | $toplevel[$partof]['p'][] = ['u' => $part['u']]; |
||
| 410 | } else { |
||
| 411 | $toplevel[$part['u']] = $part; |
||
| 412 | } |
||
| 413 | } |
||
| 414 | } |
||
| 415 | // Save list of documents. |
||
| 416 | $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(DocumentList::class); |
||
| 417 | $list->reset(); |
||
| 418 | $list->add(array_values($toplevel)); |
||
| 419 | $listMetadata['options']['numberOfToplevelHits'] = count($list); |
||
| 420 | $list->metadata = $listMetadata; |
||
| 421 | $list->sort('title'); |
||
| 422 | $list->save(); |
||
| 423 | // Clean output buffer. |
||
| 424 | ob_end_clean(); |
||
| 425 | // Send headers. |
||
| 426 | header('Location: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL(['parameter' => $this->conf['targetPid']]))); |
||
| 427 | exit; |
||
| 428 | } |
||
| 430 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths