We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 57 |
Paths | 126 |
Total Lines | 179 |
Code Lines | 118 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
158 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
159 | { |
||
160 | // Save original data array. |
||
161 | $cObjData = $this->cObj->data; |
||
162 | // Get list of metadata to show. |
||
163 | $metaList = []; |
||
164 | if ($useOriginalIiifManifestMetadata) { |
||
165 | if ($this->settings['iiifMetadataWrap']) { |
||
166 | $iiifwrap = $this->parseTS($this->settings['iiifMetadataWrap']); |
||
167 | } else { |
||
168 | $iiifwrap['key.']['wrap'] = '<dt>|</dt>'; |
||
169 | $iiifwrap['value.']['required'] = 1; |
||
170 | $iiifwrap['value.']['wrap'] = '<dd>|</dd>'; |
||
171 | } |
||
172 | $iiifLink = []; |
||
173 | $iiifLink['key.']['wrap'] = '<dt>|</dt>'; |
||
174 | $iiifLink['value.']['required'] = 1; |
||
175 | $iiifLink['value.']['setContentToCurrent'] = 1; |
||
176 | $iiifLink['value.']['typolink.']['parameter.']['current'] = 1; |
||
177 | $iiifLink['value.']['typolink.']['forceAbsoluteUrl'] = !empty($this->settings['forceAbsoluteUrl']) ? 1 : 0; |
||
178 | $iiifLink['value.']['typolink.']['forceAbsoluteUrl.']['scheme'] = !empty($this->settings['forceAbsoluteUrl']) && !empty($this->settings['forceAbsoluteUrlHttps']) ? 'https' : 'http'; |
||
179 | $iiifLink['value.']['wrap'] = '<dd>|</dd>'; |
||
180 | foreach ($metadataArray as $metadata) { |
||
181 | foreach ($metadata as $key => $group) { |
||
182 | $markerArray['METADATA'] = '<span class="tx-dlf-metadata-group">' . $this->pi_getLL($key) . '</span>'; |
||
183 | // Reset content object's data array. |
||
184 | $this->cObj->data = $cObjData; |
||
185 | if (!is_array($group)) { |
||
186 | if ($key == '_id') { |
||
187 | continue; |
||
188 | } |
||
189 | $this->cObj->data[$key] = $group; |
||
190 | if ( |
||
191 | IRI::isAbsoluteIri($this->cObj->data[$key]) |
||
192 | && (($scheme = (new IRI($this->cObj->data[$key]))->getScheme()) == 'http' || $scheme == 'https') |
||
193 | ) { |
||
194 | $field = $this->cObj->stdWrap('', $iiifLink['key.']); |
||
195 | $field .= $this->cObj->stdWrap($this->cObj->data[$key], $iiifLink['value.']); |
||
196 | } else { |
||
197 | $field = $this->cObj->stdWrap('', $iiifwrap['key.']); |
||
198 | $field .= $this->cObj->stdWrap($this->cObj->data[$key], $iiifwrap['value.']); |
||
199 | } |
||
200 | $markerArray['METADATA'] .= $this->cObj->stdWrap($field, $iiifwrap['all.']); |
||
201 | } else { |
||
202 | // Load all the metadata values into the content object's data array. |
||
203 | foreach ($group as $label => $value) { |
||
204 | if ($label == '_id') { |
||
205 | continue; |
||
206 | } |
||
207 | if (is_array($value)) { |
||
208 | $this->cObj->data[$label] = implode($this->settings['separator'], $value); |
||
209 | } else { |
||
210 | $this->cObj->data[$label] = $value; |
||
211 | } |
||
212 | if (IRI::isAbsoluteIri($this->cObj->data[$label]) && (($scheme = (new IRI($this->cObj->data[$label]))->getScheme()) == 'http' || $scheme == 'https')) { |
||
213 | $nolabel = $this->cObj->data[$label] == $label; |
||
214 | $field = $this->cObj->stdWrap($nolabel ? '' : htmlspecialchars($label), $iiifLink['key.']); |
||
215 | $field .= $this->cObj->stdWrap($this->cObj->data[$label], $iiifLink['value.']); |
||
216 | } else { |
||
217 | $field = $this->cObj->stdWrap(htmlspecialchars($label), $iiifwrap['key.']); |
||
218 | $field .= $this->cObj->stdWrap($this->cObj->data[$label], $iiifwrap['value.']); |
||
219 | } |
||
220 | $markerArray['METADATA'] .= $this->cObj->stdWrap($field, $iiifwrap['all.']); |
||
221 | } |
||
222 | } |
||
223 | } |
||
224 | } |
||
225 | } else { |
||
226 | $metadataResult = $this->metadataRepository->getMetadata($this->settings['pages'], $GLOBALS['TSFE']->sys_language_uid); |
||
227 | |||
228 | /** @var Metadata $metadata */ |
||
229 | foreach ($metadataResult as $metadata) { |
||
230 | if ($metadata && $metadata->getSysLanguageUid() != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) { |
||
231 | $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_metadata', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
232 | } |
||
233 | if ($metadata) { |
||
234 | if ($this->settings['showFull'] || $metadata->getIsListed()) { |
||
235 | $metaList[$metadata->getIndexName()] = [ |
||
236 | 'wrap' => $metadata->getWrap(), |
||
237 | 'label' => Helper::translate($metadata->getIndexName(), 'tx_dlf_metadata', $this->settings['pages']) |
||
238 | ]; |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | |||
243 | $collections = $this->collectionRepository->getCollectionForMetadata($this->settings['pages']); |
||
244 | |||
245 | /** @var Collection $collection */ |
||
246 | foreach ($collections as $collection) { |
||
247 | $collList[] = $collection->getIndexName(); |
||
248 | } |
||
249 | |||
250 | // Parse the metadata arrays. |
||
251 | foreach ($metadataArray as $metadata) { |
||
252 | $markerArray['METADATA'] = ''; |
||
253 | // Reset content object's data array. |
||
254 | $this->cObj->data = $cObjData; |
||
255 | // Load all the metadata values into the content object's data array. |
||
256 | foreach ($metadata as $index_name => $value) { |
||
257 | if (is_array($value)) { |
||
258 | $this->cObj->data[$index_name] = implode($this->settings['separator'], $value); |
||
259 | } else { |
||
260 | $this->cObj->data[$index_name] = $value; |
||
261 | } |
||
262 | } |
||
263 | // Process each metadate. |
||
264 | foreach ($metaList as $index_name => $metaConf) { |
||
265 | $parsedValue = ''; |
||
266 | $fieldwrap = $this->parseTS($metaConf['wrap']); |
||
267 | do { |
||
268 | $value = @array_shift($metadata[$index_name]); |
||
269 | if ($index_name == 'title') { |
||
270 | // Get title of parent document if needed. |
||
271 | if (empty($value) && $this->settings['getTitle'] && $this->doc->parentId) { |
||
272 | $superiorTitle = Document::getTitle($this->doc->parentId, true); |
||
273 | if (!empty($superiorTitle)) { |
||
274 | $value = '[' . $superiorTitle . ']'; |
||
275 | } |
||
276 | } |
||
277 | if (!empty($value)) { |
||
278 | $value = htmlspecialchars($value); |
||
279 | // Link title to pageview. |
||
280 | if ($this->settings['linkTitle'] && $metadata['_id']) { |
||
281 | $details = $this->doc->getLogicalStructure($metadata['_id']); |
||
282 | $uri = $this->uriBuilder->reset() |
||
283 | ->setArguments([ |
||
284 | $this->prefixId => [ |
||
285 | 'id' => $this->doc->uid, |
||
286 | 'page' => (!empty($details['points']) ? intval($details['points']) : 1) |
||
287 | ] |
||
288 | ]) |
||
289 | ->setTargetPageUid($this->settings['targetPid']) |
||
290 | ->build(); |
||
291 | $value = '<a href="' . $uri . '">' . $value . '</a>'; |
||
292 | } |
||
293 | } |
||
294 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
295 | // Translate name of holding library. |
||
296 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->settings['pages'])); |
||
297 | } elseif ($index_name == 'type' && !empty($value)) { |
||
298 | // Translate document type. |
||
299 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->settings['pages'])); |
||
300 | } elseif ($index_name == 'collection' && !empty($value)) { |
||
301 | // Check if collections isn't hidden. |
||
302 | if (in_array($value, $collList)) { |
||
303 | // Translate collection. |
||
304 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_collections', $this->settings['pages'])); |
||
305 | } else { |
||
306 | $value = ''; |
||
307 | } |
||
308 | } elseif ($index_name == 'language' && !empty($value)) { |
||
309 | // Translate ISO 639 language code. |
||
310 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
311 | } elseif (!empty($value)) { |
||
312 | // Sanitize value for output. |
||
313 | $value = htmlspecialchars($value); |
||
314 | } |
||
315 | // Hook for getting a customized value (requested by SBB). |
||
316 | foreach ($this->hookObjects as $hookObj) { |
||
317 | if (method_exists($hookObj, 'printMetadata_customizeMetadata')) { |
||
318 | $hookObj->printMetadata_customizeMetadata($value); |
||
319 | } |
||
320 | } |
||
321 | // $value might be empty for aggregation metadata fields including other "hidden" fields. |
||
322 | $value = $this->cObj->stdWrap($value, $fieldwrap['value.']); |
||
323 | if (!empty($value)) { |
||
324 | $parsedValue .= $value; |
||
325 | } |
||
326 | } while (is_array($metadata[$index_name]) && count($metadata[$index_name]) > 0); |
||
327 | |||
328 | if (!empty($parsedValue)) { |
||
329 | $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']); |
||
330 | $field .= $parsedValue; |
||
331 | $markerArray['METADATA'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']); |
||
332 | } |
||
333 | } |
||
334 | } |
||
335 | } |
||
336 | $this->view->assign('metadata', $markerArray['METADATA']); |
||
337 | } |
||
362 |