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