We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 19 |
| Paths | 1589 |
| Total Lines | 123 |
| Code Lines | 85 |
| 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 |
||
| 191 | protected function showSingleCollection($id) |
||
| 192 | { |
||
| 193 | $collection = $this->collectionRepository->getSingleCollection($this->settings, $id, $GLOBALS['TSFE']->sys_language_uid); |
||
| 194 | |||
| 195 | // Get language overlay if on alterative website language. |
||
| 196 | $pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
||
| 197 | if ($resArray = $collection->fetch()) { |
||
| 198 | if ($resArray['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content) { |
||
| 199 | $collectionData = $pageRepository->getRecordOverlay('tx_dlf_collections', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 200 | // keep the index_name of the default language |
||
| 201 | $collectionData['index_name'] = $resArray['index_name']; |
||
| 202 | } else { |
||
| 203 | $collectionData = $resArray; |
||
| 204 | } |
||
| 205 | } else { |
||
| 206 | $this->logger->warning('No collection with UID ' . $id . ' found.'); |
||
| 207 | return; |
||
| 208 | } |
||
| 209 | // Fetch corresponding document UIDs from Solr. |
||
| 210 | if ($collectionData['index_search'] != '') { |
||
| 211 | $solr_query = '(' . $collectionData['index_search'] . ')'; |
||
| 212 | } else { |
||
| 213 | $solr_query = 'collection:("' . $collectionData['index_name'] . '") AND toplevel:true'; |
||
| 214 | } |
||
| 215 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
| 216 | if (!$solr->ready) { |
||
| 217 | $this->logger->error('Apache Solr not available'); |
||
| 218 | return; |
||
| 219 | } |
||
| 220 | $params['fields'] = 'uid'; |
||
| 221 | $params['sort'] = ['uid' => 'asc']; |
||
| 222 | $solrResult = $solr->search_raw($solr_query, $params); |
||
| 223 | // Initialize array |
||
| 224 | $documentSet = []; |
||
| 225 | foreach ($solrResult as $doc) { |
||
| 226 | if ($doc->uid) { |
||
| 227 | $documentSet[] = $doc->uid; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | $documentSet = array_unique($documentSet); |
||
| 231 | |||
| 232 | $documents = $this->documentRepository->getDocumentsFromDocumentset($documentSet, $this->settings['pages']); |
||
| 233 | |||
| 234 | $toplevel = []; |
||
| 235 | $subparts = []; |
||
| 236 | $listMetadata = []; |
||
| 237 | // Process results. |
||
| 238 | /** @var Document $document */ |
||
| 239 | foreach ($documents as $document) { |
||
| 240 | if (empty($listMetadata)) { |
||
| 241 | $listMetadata = [ |
||
| 242 | 'label' => htmlspecialchars($collectionData['label']), |
||
| 243 | 'description' => $collectionData['description'], |
||
| 244 | 'thumbnail' => htmlspecialchars($collectionData['thumbnail']), |
||
| 245 | 'options' => [ |
||
| 246 | 'source' => 'collection', |
||
| 247 | 'select' => $id, |
||
| 248 | 'userid' => $collectionData['userid'], |
||
| 249 | 'params' => ['filterquery' => [['query' => 'collection_faceting:("' . $collectionData['index_name'] . '")']]], |
||
| 250 | 'core' => '', |
||
| 251 | 'pid' => $this->settings['pages'], |
||
| 252 | 'order' => 'title', |
||
| 253 | 'order.asc' => true |
||
| 254 | ] |
||
| 255 | ]; |
||
| 256 | } |
||
| 257 | // Prepare document's metadata for sorting. |
||
| 258 | $sorting = unserialize($document->getMetadataSorting()); |
||
| 259 | if (!empty($sorting['type']) && MathUtility::canBeInterpretedAsInteger($sorting['type'])) { |
||
| 260 | $sorting['type'] = Helper::getIndexNameFromUid($sorting['type'], 'tx_dlf_structures', $this->settings['pages']); |
||
| 261 | } |
||
| 262 | if (!empty($sorting['owner']) && MathUtility::canBeInterpretedAsInteger($sorting['owner'])) { |
||
| 263 | $sorting['owner'] = Helper::getIndexNameFromUid($sorting['owner'], 'tx_dlf_libraries', $this->settings['pages']); |
||
| 264 | } |
||
| 265 | if (!empty($sorting['collection']) && MathUtility::canBeInterpretedAsInteger($sorting['collection'])) { |
||
| 266 | $sorting['collection'] = Helper::getIndexNameFromUid($sorting['collection'], 'tx_dlf_collections', $this->settings['pages']); |
||
| 267 | } |
||
| 268 | // Split toplevel documents from volumes. |
||
| 269 | if ($document->getPartof() == 0) { |
||
| 270 | $toplevel[$document->getUid()] = [ |
||
| 271 | 'u' => $document->getUid(), |
||
| 272 | 'h' => '', |
||
| 273 | 's' => $sorting, |
||
| 274 | 'p' => [] |
||
| 275 | ]; |
||
| 276 | } else { |
||
| 277 | // 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. |
||
| 278 | $subparts[$document->getPartof()][$document->getVolumeSorting() . str_pad($document->getUid(), 9, '0', STR_PAD_LEFT)] = [ |
||
| 279 | 'u' => $document->getUid(), |
||
| 280 | 'h' => '', |
||
| 281 | 's' => $sorting, |
||
| 282 | 'p' => [] |
||
| 283 | ]; |
||
| 284 | } |
||
| 285 | } |
||
| 286 | |||
| 287 | // Add volumes to the corresponding toplevel documents. |
||
| 288 | foreach ($subparts as $partof => $parts) { |
||
| 289 | ksort($parts); |
||
| 290 | foreach ($parts as $part) { |
||
| 291 | if (!empty($toplevel[$partof])) { |
||
| 292 | $toplevel[$partof]['p'][] = ['u' => $part['u']]; |
||
| 293 | } else { |
||
| 294 | $toplevel[$part['u']] = $part; |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | // Save list of documents. |
||
| 299 | $list = GeneralUtility::makeInstance(DocumentList::class); |
||
| 300 | $list->reset(); |
||
| 301 | $list->add(array_values($toplevel)); |
||
| 302 | $listMetadata['options']['numberOfToplevelHits'] = count($list); |
||
| 303 | $list->metadata = $listMetadata; |
||
| 304 | $list->sort('title'); |
||
| 305 | $list->save(); |
||
| 306 | // Clean output buffer. |
||
| 307 | ob_end_clean(); |
||
| 308 | |||
| 309 | $uri = $this->uriBuilder |
||
| 310 | ->reset() |
||
| 311 | ->setTargetPageUid($this->settings['targetPid']) |
||
| 312 | ->uriFor('main', [], 'ListView', 'dlf', 'ListView'); |
||
| 313 | $this->redirectToURI($uri); |
||
| 314 | } |
||
| 316 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.