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 | $collections = $this->collectionRepository->findAll(); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (count($collections) == 1 && empty($this->settings['dont_show_single'])) { |
||
| 82 | $this->forward('show', null, null, ['collection' => array_pop($collections)]); |
||
|
|
|||
| 83 | } |
||
| 84 | |||
| 85 | $processedCollections = []; |
||
| 86 | |||
| 87 | // Process results. |
||
| 88 | foreach ($collections as $collection) { |
||
| 89 | $solr_query = ''; |
||
| 90 | if ($collection->getIndexSearch() != '') { |
||
| 91 | $solr_query .= '(' . $collection->getIndexSearch() . ')'; |
||
| 92 | } else { |
||
| 93 | $solr_query .= 'collection:("' . Solr::escapeQuery($collection->getIndexName()) . '")'; |
||
| 94 | } |
||
| 95 | $params['query'] = $solr_query . ' AND partof:0 AND toplevel:true'; |
||
| 96 | $partOfNothing = $solr->search_raw($params); |
||
| 97 | |||
| 98 | $params['query'] = $solr_query . ' AND NOT partof:0 AND toplevel:true'; |
||
| 99 | $partOfSomething = $solr->search_raw($params); |
||
| 100 | // Titles are all documents that are "root" elements i.e. partof == 0 |
||
| 101 | $collectionInfo['titles'] = []; |
||
| 102 | foreach ($partOfNothing as $doc) { |
||
| 103 | $collectionInfo['titles'][$doc->uid] = $doc->uid; |
||
| 104 | } |
||
| 105 | // Volumes are documents that are both |
||
| 106 | // a) "leaf" elements i.e. partof != 0 |
||
| 107 | // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
||
| 108 | $collectionInfo['volumes'] = $collectionInfo['titles']; |
||
| 109 | foreach ($partOfSomething as $doc) { |
||
| 110 | $collectionInfo['volumes'][$doc->uid] = $doc->uid; |
||
| 111 | // If a document is referenced via partof, it’s not a volume anymore. |
||
| 112 | unset($collectionInfo['volumes'][$doc->partof]); |
||
| 113 | } |
||
| 114 | |||
| 115 | // Generate random but unique array key taking priority into account. |
||
| 116 | do { |
||
| 117 | $_key = ($collectionInfo['priority'] * 1000) + mt_rand(0, 1000); |
||
| 118 | } while (!empty($processedCollections[$_key])); |
||
| 119 | |||
| 120 | $processedCollections[$_key]['collection'] = $collection; |
||
| 121 | $processedCollections[$_key]['info'] = $collectionInfo; |
||
| 122 | } |
||
| 123 | |||
| 124 | // Randomize sorting? |
||
| 125 | if (!empty($this->settings['randomize'])) { |
||
| 126 | ksort($processedCollections, SORT_NUMERIC); |
||
| 127 | } |
||
| 128 | |||
| 129 | $this->view->assign('collections', $processedCollections); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Show a single collection with description and all its documents. |
||
| 134 | * |
||
| 135 | * @access protected |
||
| 136 | * |
||
| 137 | * @param \Kitodo\Dlf\Domain\Model\Collection $collection: The collection object |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | public function showAction(\Kitodo\Dlf\Domain\Model\Collection $collection) |
||
| 142 | { |
||
| 143 | $searchParams = $this->getParametersSafely('searchParameter'); |
||
| 144 | |||
| 145 | // Instaniate the Solr. Without Solr present, we can't do anything. |
||
| 146 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
| 147 | if (!$solr->ready) { |
||
| 148 | $this->logger->error('Apache Solr not available'); |
||
| 149 | return; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Pagination of Results: Pass the currentPage to the fluid template to calculate current index of search result. |
||
| 153 | $widgetPage = $this->getParametersSafely('@widget_0'); |
||
| 154 | if (empty($widgetPage)) { |
||
| 205 |