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