We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 794 |
| Total Lines | 112 |
| Code Lines | 76 |
| 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 |
||
| 181 | protected function showSingleCollection(\Kitodo\Dlf\Domain\Model\Collection $collection) |
||
| 182 | { |
||
| 183 | // access storagePid from TypoScript |
||
| 184 | $pageSettings = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); |
||
| 185 | $this->settings['pages'] = $pageSettings["plugin."]["tx_dlf."]["persistence."]["storagePid"]; |
||
| 186 | |||
| 187 | // Fetch corresponding document UIDs from Solr. |
||
| 188 | if ($collection->getIndexSearch() != '') { |
||
| 189 | $solr_query = '(' . $collection->getIndexSearch() . ')'; |
||
| 190 | } else { |
||
| 191 | $solr_query = 'collection:("' . Solr::escapeQuery($collection->getIndexName()) . '") AND toplevel:true'; |
||
| 192 | } |
||
| 193 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
| 194 | if (!$solr->ready) { |
||
| 195 | $this->logger->error('Apache Solr not available'); |
||
| 196 | return; |
||
| 197 | } |
||
| 198 | $params['fields'] = 'uid'; |
||
| 199 | $params['sort'] = ['uid' => 'asc']; |
||
| 200 | $solrResult = $solr->search_raw($solr_query, $params); |
||
| 201 | // Initialize array |
||
| 202 | $documentSet = []; |
||
| 203 | foreach ($solrResult as $doc) { |
||
| 204 | if ($doc->uid) { |
||
| 205 | $documentSet[] = $doc->uid; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | $documentSet = array_unique($documentSet); |
||
| 209 | |||
| 210 | $this->settings['documentSets'] = implode(',', $documentSet); |
||
| 211 | |||
| 212 | $documents = $this->documentRepository->findDocumentsBySettings($this->settings); |
||
| 213 | |||
| 214 | $toplevel = []; |
||
| 215 | $subparts = []; |
||
| 216 | $listMetadata = []; |
||
| 217 | // Process results. |
||
| 218 | /** @var Document $document */ |
||
| 219 | foreach ($documents as $document) { |
||
| 220 | if (empty($listMetadata)) { |
||
| 221 | $listMetadata = [ |
||
| 222 | 'label' => htmlspecialchars($collection->getLabel()), |
||
| 223 | 'description' => $collection->getDescription(), |
||
| 224 | 'thumbnail' => htmlspecialchars($collection->getThumbnail()), |
||
| 225 | 'options' => [ |
||
| 226 | 'source' => 'collection', |
||
| 227 | 'select' => $id, |
||
| 228 | 'userid' => $collection->getFeCruserId(), |
||
| 229 | 'params' => ['filterquery' => [['query' => 'collection_faceting:("' . $collection->getIndexName() . '")']]], |
||
| 230 | 'core' => '', |
||
| 231 | 'order' => 'title', |
||
| 232 | 'order.asc' => true |
||
| 233 | ] |
||
| 234 | ]; |
||
| 235 | } |
||
| 236 | // Prepare document's metadata for sorting. |
||
| 237 | $sorting = unserialize($document->getMetadataSorting()); |
||
| 238 | if (!empty($sorting['type']) && MathUtility::canBeInterpretedAsInteger($sorting['type'])) { |
||
| 239 | $sorting['type'] = Helper::getIndexNameFromUid($sorting['type'], 'tx_dlf_structures', $this->settings['pages']); |
||
| 240 | } |
||
| 241 | if (!empty($sorting['owner']) && MathUtility::canBeInterpretedAsInteger($sorting['owner'])) { |
||
| 242 | $sorting['owner'] = Helper::getIndexNameFromUid($sorting['owner'], 'tx_dlf_libraries', $this->settings['pages']); |
||
| 243 | } |
||
| 244 | if (!empty($sorting['collection']) && MathUtility::canBeInterpretedAsInteger($sorting['collection'])) { |
||
| 245 | $sorting['collection'] = Helper::getIndexNameFromUid($sorting['collection'], 'tx_dlf_collections', $this->settings['pages']); |
||
| 246 | } |
||
| 247 | // Split toplevel documents from volumes. |
||
| 248 | if ($document->getPartof() == 0) { |
||
| 249 | $toplevel[$document->getUid()] = [ |
||
| 250 | 'u' => $document->getUid(), |
||
| 251 | 'h' => '', |
||
| 252 | 's' => $sorting, |
||
| 253 | 'p' => [] |
||
| 254 | ]; |
||
| 255 | } else { |
||
| 256 | // 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. |
||
| 257 | $subparts[$document->getPartof()][$document->getVolumeSorting() . str_pad($document->getUid(), 9, '0', STR_PAD_LEFT)] = [ |
||
| 258 | 'u' => $document->getUid(), |
||
| 259 | 'h' => '', |
||
| 260 | 's' => $sorting, |
||
| 261 | 'p' => [] |
||
| 262 | ]; |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | // Add volumes to the corresponding toplevel documents. |
||
| 267 | foreach ($subparts as $partof => $parts) { |
||
| 268 | ksort($parts); |
||
| 269 | foreach ($parts as $part) { |
||
| 270 | if (!empty($toplevel[$partof])) { |
||
| 271 | $toplevel[$partof]['p'][] = ['u' => $part['u']]; |
||
| 272 | } else { |
||
| 273 | $toplevel[$part['u']] = $part; |
||
| 274 | } |
||
| 275 | } |
||
| 276 | } |
||
| 277 | // Save list of documents. |
||
| 278 | $list = GeneralUtility::makeInstance(DocumentList::class); |
||
| 279 | $list->reset(); |
||
| 280 | $list->add(array_values($toplevel)); |
||
| 281 | $listMetadata['options']['numberOfToplevelHits'] = count($list); |
||
| 282 | $list->metadata = $listMetadata; |
||
| 283 | $list->sort('title'); |
||
| 284 | $list->save(); |
||
| 285 | // Clean output buffer. |
||
| 286 | ob_end_clean(); |
||
| 287 | |||
| 288 | $uri = $this->uriBuilder |
||
| 289 | ->reset() |
||
| 290 | ->setTargetPageUid($this->settings['targetPid']) |
||
| 291 | ->uriFor('main', [], 'ListView', 'dlf', 'ListView'); |
||
| 292 | $this->redirectToURI($uri); |
||
| 293 | } |
||
| 295 |
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.