We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 31 |
Paths | > 20000 |
Total Lines | 177 |
Code Lines | 120 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 |
||
80 | protected function showCollectionList() |
||
81 | { |
||
82 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
83 | ->getQueryBuilderForTable('tx_dlf_collections'); |
||
84 | |||
85 | $selectedCollections = $queryBuilder->expr()->neq('tx_dlf_collections.uid', 0); |
||
86 | $orderBy = 'tx_dlf_collections.label'; |
||
87 | $showUserDefinedColls = ''; |
||
88 | // Handle collections set by configuration. |
||
89 | if ($this->conf['collections']) { |
||
90 | if ( |
||
91 | count(explode(',', $this->conf['collections'])) == 1 |
||
92 | && empty($this->conf['dont_show_single']) |
||
93 | ) { |
||
94 | $this->showSingleCollection(intval(trim($this->conf['collections'], ' ,'))); |
||
95 | } |
||
96 | $selectedCollections = $queryBuilder->expr()->in('tx_dlf_collections.uid', implode(',', GeneralUtility::intExplode(',', $this->conf['collections']))); |
||
97 | } |
||
98 | // Should user-defined collections be shown? |
||
99 | if (empty($this->conf['show_userdefined'])) { |
||
100 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
||
101 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
102 | if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { |
||
103 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', intval($GLOBALS['TSFE']->fe_user->user['uid'])); |
||
104 | } else { |
||
105 | $showUserDefinedColls = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | // Get collections. |
||
110 | $queryBuilder |
||
111 | ->select( |
||
112 | 'tx_dlf_collections.uid AS uid', // required by getRecordOverlay() |
||
113 | 'tx_dlf_collections.pid AS pid', // required by getRecordOverlay() |
||
114 | 'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay() |
||
115 | 'tx_dlf_collections.index_name AS index_name', |
||
116 | 'tx_dlf_collections.index_search as index_query', |
||
117 | 'tx_dlf_collections.label AS label', |
||
118 | 'tx_dlf_collections.thumbnail AS thumbnail', |
||
119 | 'tx_dlf_collections.description AS description', |
||
120 | 'tx_dlf_collections.priority AS priority' |
||
121 | ) |
||
122 | ->from('tx_dlf_collections') |
||
123 | ->where( |
||
124 | $selectedCollections, |
||
125 | $showUserDefinedColls, |
||
126 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->conf['pages'])), |
||
127 | $queryBuilder->expr()->andX( |
||
128 | $queryBuilder->expr()->orX( |
||
129 | $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]), |
||
130 | $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $GLOBALS['TSFE']->sys_language_uid) |
||
131 | ), |
||
132 | $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0) |
||
133 | ) |
||
134 | ) |
||
135 | ->orderBy($orderBy); |
||
136 | |||
137 | $result = $queryBuilder->execute(); |
||
138 | $count = $queryBuilder->count('uid')->execute()->fetchColumn(0); |
||
139 | $content = ''; |
||
140 | if ($count == 1 && empty($this->conf['dont_show_single'])) { |
||
141 | $resArray = $result->fetch(); |
||
142 | $this->showSingleCollection(intval($resArray['uid'])); |
||
143 | } |
||
144 | $solr = Solr::getInstance($this->conf['solrcore']); |
||
145 | if (!$solr->ready) { |
||
146 | Helper::devLog('Apache Solr not available', DEVLOG_SEVERITY_ERROR); |
||
147 | return $content; |
||
148 | } |
||
149 | // We only care about the UID and partOf in the results and want them sorted |
||
150 | $params['fields'] = 'uid,partof'; |
||
151 | $params['sort'] = ['uid' => 'asc']; |
||
152 | $collections = []; |
||
153 | |||
154 | // Get language overlay if on alterative website language. |
||
155 | $pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class); |
||
|
|||
156 | while ($collectionData = $result->fetch()) { |
||
157 | if ($collectionData['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content) { |
||
158 | $collections[$collectionData['uid']] = $pageRepository->getRecordOverlay('tx_dlf_collections', $collectionData, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
159 | // keep the index_name of the default language |
||
160 | $collections[$collectionData['uid']]['index_name'] = $collectionData['index_name']; |
||
161 | } else { |
||
162 | $collections[$collectionData['uid']] = $collectionData; |
||
163 | } |
||
164 | } |
||
165 | // Sort collections according to flexform configuration |
||
166 | if ($this->conf['collections']) { |
||
167 | $sortedCollections = []; |
||
168 | foreach (GeneralUtility::intExplode(',', $this->conf['collections']) as $uid) { |
||
169 | $sortedCollections[$uid] = $collections[$uid]; |
||
170 | } |
||
171 | $collections = $sortedCollections; |
||
172 | } |
||
173 | $markerArray = []; |
||
174 | // Process results. |
||
175 | foreach ($collections as $collection) { |
||
176 | $solr_query = ''; |
||
177 | if ($collection['index_query'] != '') { |
||
178 | $solr_query .= '(' . $collection['index_query'] . ')'; |
||
179 | } else { |
||
180 | $solr_query .= 'collection:("' . $collection['index_name'] . '")'; |
||
181 | } |
||
182 | $partOfNothing = $solr->search_raw($solr_query . ' AND partof:0 AND toplevel:true', $params); |
||
183 | $partOfSomething = $solr->search_raw($solr_query . ' AND NOT partof:0 AND toplevel:true', $params); |
||
184 | // Titles are all documents that are "root" elements i.e. partof == 0 |
||
185 | $collection['titles'] = []; |
||
186 | foreach ($partOfNothing as $doc) { |
||
187 | $collection['titles'][$doc->uid] = $doc->uid; |
||
188 | } |
||
189 | // Volumes are documents that are both |
||
190 | // a) "leaf" elements i.e. partof != 0 |
||
191 | // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
||
192 | $collection['volumes'] = $collection['titles']; |
||
193 | foreach ($partOfSomething as $doc) { |
||
194 | $collection['volumes'][$doc->uid] = $doc->uid; |
||
195 | // If a document is referenced via partof, it’s not a volume anymore. |
||
196 | unset($collection['volumes'][$doc->partof]); |
||
197 | } |
||
198 | // Generate random but unique array key taking priority into account. |
||
199 | do { |
||
200 | $_key = ($collection['priority'] * 1000) + mt_rand(0, 1000); |
||
201 | } while (!empty($markerArray[$_key])); |
||
202 | // Merge plugin variables with new set of values. |
||
203 | $additionalParams = ['collection' => $collection['uid']]; |
||
204 | if (is_array($this->piVars)) { |
||
205 | $piVars = $this->piVars; |
||
206 | unset($piVars['DATA']); |
||
207 | $additionalParams = Helper::mergeRecursiveWithOverrule($piVars, $additionalParams); |
||
208 | } |
||
209 | // Build typolink configuration array. |
||
210 | $conf = [ |
||
211 | 'useCacheHash' => 1, |
||
212 | 'parameter' => $GLOBALS['TSFE']->id, |
||
213 | 'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
||
214 | 'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
||
215 | 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', true, false) |
||
216 | ]; |
||
217 | // Link collection's title to list view. |
||
218 | $markerArray[$_key]['###TITLE###'] = $this->cObj->typoLink(htmlspecialchars($collection['label']), $conf); |
||
219 | // Add feed link if applicable. |
||
220 | if (!empty($this->conf['targetFeed'])) { |
||
221 | $img = '<img src="' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey)) . 'Resources/Public/Icons/txdlffeeds.png" alt="' . htmlspecialchars($this->pi_getLL('feedAlt', '')) . '" title="' . htmlspecialchars($this->pi_getLL('feedTitle', '')) . '" />'; |
||
222 | $markerArray[$_key]['###FEED###'] = $this->pi_linkTP($img, [$this->prefixId => ['collection' => $collection['uid']]], false, $this->conf['targetFeed']); |
||
223 | } else { |
||
224 | $markerArray[$_key]['###FEED###'] = ''; |
||
225 | } |
||
226 | // Add thumbnail. |
||
227 | if (!empty($collection['thumbnail'])) { |
||
228 | $markerArray[$_key]['###THUMBNAIL###'] = '<img alt="" title="' . htmlspecialchars($collection['label']) . '" src="' . $collection['thumbnail'] . '" />'; |
||
229 | } else { |
||
230 | $markerArray[$_key]['###THUMBNAIL###'] = ''; |
||
231 | } |
||
232 | // Add description. |
||
233 | $markerArray[$_key]['###DESCRIPTION###'] = $this->pi_RTEcssText($collection['description']); |
||
234 | // Build statistic's output. |
||
235 | $labelTitles = $this->pi_getLL((count($collection['titles']) > 1 ? 'titles' : 'title'), ''); |
||
236 | $markerArray[$_key]['###COUNT_TITLES###'] = htmlspecialchars(count($collection['titles']) . $labelTitles); |
||
237 | $labelVolumes = $this->pi_getLL((count($collection['volumes']) > 1 ? 'volumes' : 'volume'), ''); |
||
238 | $markerArray[$_key]['###COUNT_VOLUMES###'] = htmlspecialchars(count($collection['volumes']) . $labelVolumes); |
||
239 | } |
||
240 | // Randomize sorting? |
||
241 | if (!empty($this->conf['randomize'])) { |
||
242 | ksort($markerArray, SORT_NUMERIC); |
||
243 | // Don't cache the output. |
||
244 | $this->setCache(false); |
||
245 | } |
||
246 | $entry = $this->templateService->getSubpart($this->template, '###ENTRY###'); |
||
247 | foreach ($markerArray as $marker) { |
||
248 | $content .= $this->templateService->substituteMarkerArray($entry, $marker); |
||
249 | } |
||
250 | // Hook for getting custom collection hierarchies/subentries (requested by SBB). |
||
251 | foreach ($this->hookObjects as $hookObj) { |
||
252 | if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) { |
||
253 | $hookObj->showCollectionList_getCustomCollectionList($this, $this->conf['templateFile'], $content, $markerArray); |
||
254 | } |
||
255 | } |
||
256 | return $this->templateService->substituteSubpart($this->template, '###ENTRY###', $content, true); |
||
257 | } |
||
445 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths