We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 7 |
| Paths | 25 |
| Total Lines | 64 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 142 | public function showAction(\Kitodo\Dlf\Domain\Model\Collection $collection) |
||
| 143 | { |
||
| 144 | // Instaniate the Solr. Without Solr present, we can't do anything. |
||
| 145 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
| 146 | if (!$solr->ready) { |
||
| 147 | $this->logger->error('Apache Solr not available'); |
||
| 148 | return; |
||
| 149 | } |
||
| 150 | |||
| 151 | // Check if it's a virtual collection with an Solr query set. |
||
| 152 | if ($collection->getIndexSearch() != '') { |
||
| 153 | $solr_query = '(' . $collection->getIndexSearch() . ')'; |
||
| 154 | } else { |
||
| 155 | $solr_query = 'collection:("' . Solr::escapeQuery($collection->getIndexName()) . '") AND toplevel:true'; |
||
| 156 | } |
||
| 157 | |||
| 158 | // We only fetch the UIDs of the found toplevel documents. |
||
| 159 | $params['fields'] = 'uid'; |
||
| 160 | $params['sort'] = ['uid' => 'asc']; |
||
| 161 | $params['query'] = $solr_query; |
||
| 162 | $solrResult = $solr->search_raw($params); |
||
| 163 | |||
| 164 | // Initialize array |
||
| 165 | $documentSet = []; |
||
| 166 | foreach ($solrResult as $doc) { |
||
| 167 | if ($doc->uid) { |
||
| 168 | $documentSet[] = $doc->uid; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | $documentSet = array_unique($documentSet); |
||
| 172 | |||
| 173 | $this->settings['documentSets'] = implode(',', $documentSet); |
||
| 174 | |||
| 175 | // Now find document objects for the given UIDs. |
||
| 176 | $documents = $this->documentRepository->findDocumentsBySettings($this->settings); |
||
| 177 | |||
| 178 | // If a targetPid is given, the results will be shown by ListView on the target page. |
||
| 179 | if (!empty($this->settings['targetPid'])) { |
||
| 180 | $this->redirect('main', 'ListView', null, |
||
| 181 | [ |
||
| 182 | 'searchParameter' => $searchParams, |
||
| 183 | 'widgetPage' => $widgetPage, |
||
| 184 | 'solrcore' => $this->settings['solrcore'] |
||
| 185 | ], $this->settings['targetPid'] |
||
| 186 | ); |
||
| 187 | } |
||
| 188 | |||
| 189 | // Pagination of Results: Pass the currentPage to the fluid template to calculate current index of search result. |
||
| 190 | $widgetPage = $this->getParametersSafely('@widget_0'); |
||
| 191 | if (empty($widgetPage)) { |
||
| 192 | $widgetPage = ['currentPage' => 1]; |
||
| 193 | } |
||
| 194 | |||
| 195 | // get all sortable metadata records |
||
| 196 | $sortableMetadata = $this->metadataRepository->findByIsSortable(true); |
||
| 197 | |||
| 198 | // get all metadata records to be shown in results |
||
| 199 | $listedMetadata = $this->metadataRepository->findByIsListed(true); |
||
| 200 | |||
| 201 | $this->view->assign('documents', $documents); |
||
| 202 | $this->view->assign('collection', $collection); |
||
| 203 | $this->view->assign('widgetPage', $widgetPage); |
||
| 204 | $this->view->assign('sortableMetadata', $sortableMetadata); |
||
| 205 | $this->view->assign('listedMetadata', $listedMetadata); |
||
| 206 | |||
| 209 |