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