We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 12 |
| Paths | 73 |
| Total Lines | 76 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 78 | protected function showCollectionList() |
||
| 79 | { |
||
| 80 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
| 81 | |||
| 82 | if (!$solr->ready) { |
||
| 83 | $this->logger->error('Apache Solr not available'); |
||
| 84 | return; |
||
| 85 | } |
||
| 86 | // We only care about the UID and partOf in the results and want them sorted |
||
| 87 | $params['fields'] = 'uid,partof'; |
||
| 88 | $params['sort'] = ['uid' => 'asc']; |
||
| 89 | $collections = []; |
||
| 90 | |||
| 91 | // Sort collections according to flexform configuration |
||
| 92 | if ($this->settings['collections']) { |
||
| 93 | $sortedCollections = []; |
||
| 94 | foreach (GeneralUtility::intExplode(',', $this->settings['collections']) as $uid) { |
||
| 95 | $sortedCollections[$uid] = $this->collectionRepository->findByUid($uid); |
||
| 96 | } |
||
| 97 | $collections = $sortedCollections; |
||
| 98 | } |
||
| 99 | |||
| 100 | if (count($collections) == 1 && empty($this->settings['dont_show_single'])) { |
||
| 101 | $this->showSingleCollection(array_pop($collections)); |
||
| 102 | } |
||
| 103 | |||
| 104 | $processedCollections = []; |
||
| 105 | |||
| 106 | // Process results. |
||
| 107 | foreach ($collections as $collection) { |
||
| 108 | $solr_query = ''; |
||
| 109 | if ($collection->getIndexSearch() != '') { |
||
| 110 | $solr_query .= '(' . $collection->getIndexSearch() . ')'; |
||
| 111 | } else { |
||
| 112 | $solr_query .= 'collection:("' . Solr::escapeQuery($collection->getIndexName()) . '")'; |
||
| 113 | } |
||
| 114 | $partOfNothing = $solr->search_raw($solr_query . ' AND partof:0 AND toplevel:true', $params); |
||
| 115 | $partOfSomething = $solr->search_raw($solr_query . ' AND NOT partof:0 AND toplevel:true', $params); |
||
| 116 | // Titles are all documents that are "root" elements i.e. partof == 0 |
||
| 117 | $collectionInfo['titles'] = []; |
||
| 118 | foreach ($partOfNothing as $doc) { |
||
| 119 | $collectionInfo['titles'][$doc->uid] = $doc->uid; |
||
| 120 | } |
||
| 121 | // Volumes are documents that are both |
||
| 122 | // a) "leaf" elements i.e. partof != 0 |
||
| 123 | // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
||
| 124 | $collectionInfo['volumes'] = $collectionInfo['titles']; |
||
| 125 | foreach ($partOfSomething as $doc) { |
||
| 126 | $collectionInfo['volumes'][$doc->uid] = $doc->uid; |
||
| 127 | // If a document is referenced via partof, it’s not a volume anymore. |
||
| 128 | unset($collectionInfo['volumes'][$doc->partof]); |
||
| 129 | } |
||
| 130 | |||
| 131 | // Generate random but unique array key taking priority into account. |
||
| 132 | do { |
||
| 133 | $_key = ($collectionInfo['priority'] * 1000) + mt_rand(0, 1000); |
||
| 134 | } while (!empty($processedCollections[$_key])); |
||
| 135 | |||
| 136 | $processedCollections[$_key]['collection'] = $collection; |
||
| 137 | $processedCollections[$_key]['info'] = $collectionInfo; |
||
| 138 | } |
||
| 139 | |||
| 140 | // Randomize sorting? |
||
| 141 | if (!empty($this->settings['randomize'])) { |
||
| 142 | ksort($processedCollections, SORT_NUMERIC); |
||
| 143 | } |
||
| 144 | |||
| 145 | // TODO: Hook for getting custom collection hierarchies/subentries (requested by SBB). |
||
| 146 | /* foreach ($this->hookObjects as $hookObj) { |
||
| 147 | if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) { |
||
| 148 | $hookObj->showCollectionList_getCustomCollectionList($this, $this->settings['templateFile'], $content, $markerArray); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | */ |
||
| 152 | |||
| 153 | $this->view->assign('collections', $processedCollections); |
||
| 154 | } |
||
| 279 |