We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 20 |
Paths | 5184 |
Total Lines | 147 |
Code Lines | 88 |
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 |
||
65 | protected function showCollectionList() |
||
66 | { |
||
67 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
68 | ->getQueryBuilderForTable('tx_dlf_collections'); |
||
69 | |||
70 | $selectedCollections = $queryBuilder->expr()->neq('tx_dlf_collections.uid', 0); |
||
71 | $orderBy = 'tx_dlf_collections.label'; |
||
72 | $showUserDefinedColls = ''; |
||
73 | // Handle collections set by configuration. |
||
74 | if ($this->settings['collections']) { |
||
75 | if ( |
||
76 | count(explode(',', $this->settings['collections'])) == 1 |
||
77 | && empty($this->settings['dont_show_single']) |
||
78 | ) { |
||
79 | $this->showSingleCollection(intval(trim($this->settings['collections'], ' ,'))); |
||
80 | } |
||
81 | $selectedCollections = $queryBuilder->expr()->in('tx_dlf_collections.uid', implode(',', GeneralUtility::intExplode(',', $this->settings['collections']))); |
||
82 | } |
||
83 | |||
84 | // Should user-defined collections be shown? |
||
85 | if (empty($this->settings['show_userdefined'])) { |
||
86 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
||
87 | } elseif ($this->settings['show_userdefined'] > 0) { |
||
88 | if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { |
||
89 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', intval($GLOBALS['TSFE']->fe_user->user['uid'])); |
||
90 | } else { |
||
91 | $showUserDefinedColls = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | // Get collections. |
||
96 | $queryBuilder |
||
97 | ->select( |
||
98 | 'tx_dlf_collections.uid AS uid', // required by getRecordOverlay() |
||
99 | 'tx_dlf_collections.pid AS pid', // required by getRecordOverlay() |
||
100 | 'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay() |
||
101 | 'tx_dlf_collections.index_name AS index_name', |
||
102 | 'tx_dlf_collections.index_search as index_query', |
||
103 | 'tx_dlf_collections.label AS label', |
||
104 | 'tx_dlf_collections.thumbnail AS thumbnail', |
||
105 | 'tx_dlf_collections.description AS description', |
||
106 | 'tx_dlf_collections.priority AS priority' |
||
107 | ) |
||
108 | ->from('tx_dlf_collections') |
||
109 | ->where( |
||
110 | $selectedCollections, |
||
111 | $showUserDefinedColls, |
||
112 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->settings['pages'])), |
||
113 | $queryBuilder->expr()->andX( |
||
114 | $queryBuilder->expr()->orX( |
||
115 | $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]), |
||
116 | $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $GLOBALS['TSFE']->sys_language_uid) |
||
117 | ), |
||
118 | $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0) |
||
119 | ) |
||
120 | ) |
||
121 | ->orderBy($orderBy); |
||
122 | |||
123 | $result = $queryBuilder->execute(); |
||
124 | $count = $queryBuilder->count('uid')->execute()->fetchColumn(0); |
||
125 | |||
126 | if ($count == 1 && empty($this->settings['dont_show_single'])) { |
||
127 | $resArray = $result->fetch(); |
||
128 | $this->showSingleCollection(intval($resArray['uid'])); |
||
129 | } |
||
130 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
131 | if (!$solr->ready) { |
||
132 | $this->logger->error('Apache Solr not available'); |
||
133 | //return $content; |
||
134 | } |
||
135 | // We only care about the UID and partOf in the results and want them sorted |
||
136 | $params['fields'] = 'uid,partof'; |
||
137 | $params['sort'] = ['uid' => 'asc']; |
||
138 | $collections = []; |
||
139 | |||
140 | // Get language overlay if on alterative website language. |
||
141 | $pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
||
142 | while ($collectionData = $result->fetch()) { |
||
143 | if ($collectionData['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content) { |
||
144 | $collections[$collectionData['uid']] = $pageRepository->getRecordOverlay('tx_dlf_collections', $collectionData, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
145 | // keep the index_name of the default language |
||
146 | $collections[$collectionData['uid']]['index_name'] = $collectionData['index_name']; |
||
147 | } else { |
||
148 | $collections[$collectionData['uid']] = $collectionData; |
||
149 | } |
||
150 | } |
||
151 | // Sort collections according to flexform configuration |
||
152 | if ($this->settings['collections']) { |
||
153 | $sortedCollections = []; |
||
154 | foreach (GeneralUtility::intExplode(',', $this->settings['collections']) as $uid) { |
||
155 | $sortedCollections[$uid] = $collections[$uid]; |
||
156 | } |
||
157 | $collections = $sortedCollections; |
||
158 | } |
||
159 | |||
160 | $processedCollections = []; |
||
161 | |||
162 | // Process results. |
||
163 | foreach ($collections as $collection) { |
||
164 | $solr_query = ''; |
||
165 | if ($collection['index_query'] != '') { |
||
166 | $solr_query .= '(' . $collection['index_query'] . ')'; |
||
167 | } else { |
||
168 | $solr_query .= 'collection:("' . $collection['index_name'] . '")'; |
||
169 | } |
||
170 | $partOfNothing = $solr->search_raw($solr_query . ' AND partof:0 AND toplevel:true', $params); |
||
171 | $partOfSomething = $solr->search_raw($solr_query . ' AND NOT partof:0 AND toplevel:true', $params); |
||
172 | // Titles are all documents that are "root" elements i.e. partof == 0 |
||
173 | $collection['titles'] = []; |
||
174 | foreach ($partOfNothing as $doc) { |
||
175 | $collection['titles'][$doc->uid] = $doc->uid; |
||
176 | } |
||
177 | // Volumes are documents that are both |
||
178 | // a) "leaf" elements i.e. partof != 0 |
||
179 | // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
||
180 | $collection['volumes'] = $collection['titles']; |
||
181 | foreach ($partOfSomething as $doc) { |
||
182 | $collection['volumes'][$doc->uid] = $doc->uid; |
||
183 | // If a document is referenced via partof, it’s not a volume anymore. |
||
184 | unset($collection['volumes'][$doc->partof]); |
||
185 | } |
||
186 | |||
187 | // Generate random but unique array key taking priority into account. |
||
188 | do { |
||
189 | $_key = ($collection['priority'] * 1000) + mt_rand(0, 1000); |
||
190 | } while (!empty($processedCollections[$_key])); |
||
191 | |||
192 | $collection['countTitles'] = count($collection['titles']); |
||
193 | $collection['countVolumes'] = count($collection['volumes']); |
||
194 | |||
195 | $processedCollections[$_key] = $collection; |
||
196 | } |
||
197 | |||
198 | // Randomize sorting? |
||
199 | if (!empty($this->settings['randomize'])) { |
||
200 | ksort($processedCollections, SORT_NUMERIC); |
||
201 | } |
||
202 | |||
203 | // TODO: Hook for getting custom collection hierarchies/subentries (requested by SBB). |
||
204 | /* foreach ($this->hookObjects as $hookObj) { |
||
205 | if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) { |
||
206 | $hookObj->showCollectionList_getCustomCollectionList($this, $this->settings['templateFile'], $content, $markerArray); |
||
207 | } |
||
208 | } |
||
209 | */ |
||
210 | |||
211 | $this->view->assign('collections', $processedCollections); |
||
212 | } |
||
399 |
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.