We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 30 |
Paths | > 20000 |
Total Lines | 171 |
Code Lines | 116 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 | // We only care about the UID and partOf in the results and want them sorted |
||
146 | $params['fields'] = 'uid,partof'; |
||
147 | $params['sort'] = ['uid' => 'asc']; |
||
148 | $collections = []; |
||
149 | |||
150 | // Get language overlay if on alterative website language. |
||
151 | $pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class); |
||
|
|||
152 | while ($collectionData = $result->fetch()) { |
||
153 | if ($collectionData['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content) { |
||
154 | $collections[$collectionData['uid']] = $pageRepository->getRecordOverlay('tx_dlf_collections', $collectionData, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
155 | } else { |
||
156 | $collections[$collectionData['uid']] = $collectionData; |
||
157 | } |
||
158 | } |
||
159 | // Sort collections according to flexform configuration |
||
160 | if ($this->conf['collections']) { |
||
161 | $sortedCollections = []; |
||
162 | foreach (GeneralUtility::intExplode(',', $this->conf['collections']) as $uid) { |
||
163 | $sortedCollections[$uid] = $collections[$uid]; |
||
164 | } |
||
165 | $collections = $sortedCollections; |
||
166 | } |
||
167 | $markerArray = []; |
||
168 | // Process results. |
||
169 | foreach ($collections as $collection) { |
||
170 | $solr_query = ''; |
||
171 | if ($collection['index_query'] != '') { |
||
172 | $solr_query .= '(' . $collection['index_query'] . ')'; |
||
173 | } else { |
||
174 | $solr_query .= 'collection:("' . $collection['index_name'] . '")'; |
||
175 | } |
||
176 | $partOfNothing = $solr->search_raw($solr_query . ' AND partof:0 AND toplevel:true', $params); |
||
177 | $partOfSomething = $solr->search_raw($solr_query . ' AND NOT partof:0 AND toplevel:true', $params); |
||
178 | // Titles are all documents that are "root" elements i.e. partof == 0 |
||
179 | $collection['titles'] = []; |
||
180 | foreach ($partOfNothing as $doc) { |
||
181 | $collection['titles'][$doc->uid] = $doc->uid; |
||
182 | } |
||
183 | // Volumes are documents that are both |
||
184 | // a) "leaf" elements i.e. partof != 0 |
||
185 | // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
||
186 | $collection['volumes'] = $collection['titles']; |
||
187 | foreach ($partOfSomething as $doc) { |
||
188 | $collection['volumes'][$doc->uid] = $doc->uid; |
||
189 | // If a document is referenced via partof, it’s not a volume anymore. |
||
190 | unset($collection['volumes'][$doc->partof]); |
||
191 | } |
||
192 | // Generate random but unique array key taking priority into account. |
||
193 | do { |
||
194 | $_key = ($collection['priority'] * 1000) + mt_rand(0, 1000); |
||
195 | } while (!empty($markerArray[$_key])); |
||
196 | // Merge plugin variables with new set of values. |
||
197 | $additionalParams = ['collection' => $collection['uid']]; |
||
198 | if (is_array($this->piVars)) { |
||
199 | $piVars = $this->piVars; |
||
200 | unset($piVars['DATA']); |
||
201 | $additionalParams = Helper::mergeRecursiveWithOverrule($piVars, $additionalParams); |
||
202 | } |
||
203 | // Build typolink configuration array. |
||
204 | $conf = [ |
||
205 | 'useCacheHash' => 1, |
||
206 | 'parameter' => $GLOBALS['TSFE']->id, |
||
207 | 'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
||
208 | 'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
||
209 | 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', true, false) |
||
210 | ]; |
||
211 | // Link collection's title to list view. |
||
212 | $markerArray[$_key]['###TITLE###'] = $this->cObj->typoLink(htmlspecialchars($collection['label']), $conf); |
||
213 | // Add feed link if applicable. |
||
214 | if (!empty($this->conf['targetFeed'])) { |
||
215 | $img = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Icons/txdlffeeds.png" alt="' . $this->pi_getLL('feedAlt', '', true) . '" title="' . $this->pi_getLL('feedTitle', '', true) . '" />'; |
||
216 | $markerArray[$_key]['###FEED###'] = $this->pi_linkTP($img, [$this->prefixId => ['collection' => $collection['uid']]], false, $this->conf['targetFeed']); |
||
217 | } else { |
||
218 | $markerArray[$_key]['###FEED###'] = ''; |
||
219 | } |
||
220 | // Add thumbnail. |
||
221 | if (!empty($collection['thumbnail'])) { |
||
222 | $markerArray[$_key]['###THUMBNAIL###'] = '<img alt="" title="' . htmlspecialchars($collection['label']) . '" src="' . $collection['thumbnail'] . '" />'; |
||
223 | } else { |
||
224 | $markerArray[$_key]['###THUMBNAIL###'] = ''; |
||
225 | } |
||
226 | // Add description. |
||
227 | $markerArray[$_key]['###DESCRIPTION###'] = $this->pi_RTEcssText($collection['description']); |
||
228 | // Build statistic's output. |
||
229 | $labelTitles = $this->pi_getLL((count($collection['titles']) > 1 ? 'titles' : 'title'), '', false); |
||
230 | $markerArray[$_key]['###COUNT_TITLES###'] = htmlspecialchars(count($collection['titles']) . $labelTitles); |
||
231 | $labelVolumes = $this->pi_getLL((count($collection['volumes']) > 1 ? 'volumes' : 'volume'), '', false); |
||
232 | $markerArray[$_key]['###COUNT_VOLUMES###'] = htmlspecialchars(count($collection['volumes']) . $labelVolumes); |
||
233 | } |
||
234 | // Randomize sorting? |
||
235 | if (!empty($this->conf['randomize'])) { |
||
236 | ksort($markerArray, SORT_NUMERIC); |
||
237 | // Don't cache the output. |
||
238 | $this->setCache(false); |
||
239 | } |
||
240 | $entry = $this->templateService->getSubpart($this->template, '###ENTRY###'); |
||
241 | foreach ($markerArray as $marker) { |
||
242 | $content .= $this->templateService->substituteMarkerArray($entry, $marker); |
||
243 | } |
||
244 | // Hook for getting custom collection hierarchies/subentries (requested by SBB). |
||
245 | foreach ($this->hookObjects as $hookObj) { |
||
246 | if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) { |
||
247 | $hookObj->showCollectionList_getCustomCollectionList($this, $this->conf['templateFile'], $content, $markerArray); |
||
248 | } |
||
249 | } |
||
250 | return $this->templateService->substituteSubpart($this->template, '###ENTRY###', $content, true); |
||
251 | } |
||
437 |
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