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