We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 49 |
| Paths | 113 |
| Total Lines | 154 |
| Code Lines | 106 |
| 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 |
||
| 116 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
| 117 | { |
||
| 118 | // Load template file. |
||
| 119 | $this->getTemplate(); |
||
| 120 | $output = ''; |
||
| 121 | $subpart['block'] = $this->templateService->getSubpart($this->template, '###BLOCK###'); |
||
| 122 | // Save original data array. |
||
| 123 | $cObjData = $this->cObj->data; |
||
| 124 | // Get list of metadata to show. |
||
| 125 | $metaList = []; |
||
| 126 | if ($useOriginalIiifManifestMetadata) { |
||
| 127 | if ($this->conf['iiifMetadataWrap']) { |
||
| 128 | $iiifwrap = $this->parseTS($this->conf['iiifMetadataWrap']); |
||
| 129 | } else { |
||
| 130 | $iiifwrap['key.']['wrap'] = '<dt>|</dt>'; |
||
| 131 | $iiifwrap['value.']['required'] = 1; |
||
| 132 | $iiifwrap['value.']['wrap'] = '<dd>|</dd>'; |
||
| 133 | } |
||
| 134 | $iiifLink = []; |
||
| 135 | $iiifLink['key.']['wrap'] = '<dt>|</dt>'; |
||
| 136 | $iiifLink['value.']['required'] = 1; |
||
| 137 | $iiifLink['value.']['setContentToCurrent'] = 1; |
||
| 138 | $iiifLink['value.']['typolink.']['parameter.']['current'] = 1; |
||
| 139 | $iiifLink['value.']['typolink.']['forceAbsoluteUrl'] = !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0; |
||
| 140 | $iiifLink['value.']['typolink.']['forceAbsoluteUrl.']['scheme'] = !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'; |
||
| 141 | $iiifLink['value.']['wrap'] = '<dd>|</dd>'; |
||
| 142 | foreach ($metadataArray as $metadata) { |
||
| 143 | foreach ($metadata as $key => $group) { |
||
| 144 | $markerArray['###METADATA###'] = '<span class="tx-dlf-metadata-group">' . $this->pi_getLL($key) . '</span>'; |
||
| 145 | // Reset content object's data array. |
||
| 146 | $this->cObj->data = $cObjData; |
||
| 147 | if (!is_array($group)) { |
||
| 148 | if ($key == '_id') { |
||
| 149 | continue; |
||
| 150 | } |
||
| 151 | $this->cObj->data[$key] = $group; |
||
| 152 | if ( |
||
| 153 | IRI::isAbsoluteIri($this->cObj->data[$key]) |
||
| 154 | && (($scheme = (new IRI($this->cObj->data[$key]))->getScheme()) == 'http' || $scheme == 'https') |
||
| 155 | ) { |
||
| 156 | $field = $this->cObj->stdWrap('', $iiifLink['key.']); |
||
| 157 | $field .= $this->cObj->stdWrap($this->cObj->data[$key], $iiifLink['value.']); |
||
| 158 | } else { |
||
| 159 | $field = $this->cObj->stdWrap('', $iiifwrap['key.']); |
||
| 160 | $field .= $this->cObj->stdWrap($this->cObj->data[$key], $iiifwrap['value.']); |
||
| 161 | } |
||
| 162 | $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $iiifwrap['all.']); |
||
| 163 | } else { |
||
| 164 | // Load all the metadata values into the content object's data array. |
||
| 165 | foreach ($group as $label => $value) { |
||
| 166 | if ($label == '_id') { |
||
| 167 | continue; |
||
| 168 | } |
||
| 169 | if (is_array($value)) { |
||
| 170 | $this->cObj->data[$label] = implode($this->conf['separator'], $value); |
||
| 171 | } else { |
||
| 172 | $this->cObj->data[$label] = $value; |
||
| 173 | } |
||
| 174 | if (IRI::isAbsoluteIri($this->cObj->data[$label]) && (($scheme = (new IRI($this->cObj->data[$label]))->getScheme()) == 'http' || $scheme == 'https')) { |
||
| 175 | $nolabel = $this->cObj->data[$label] == $label; |
||
| 176 | $field = $this->cObj->stdWrap($nolabel ? '' : htmlspecialchars($label), $iiifLink['key.']); |
||
| 177 | $field .= $this->cObj->stdWrap($this->cObj->data[$label], $iiifLink['value.']); |
||
| 178 | } else { |
||
| 179 | $field = $this->cObj->stdWrap(htmlspecialchars($label), $iiifwrap['key.']); |
||
| 180 | $field .= $this->cObj->stdWrap($this->cObj->data[$label], $iiifwrap['value.']); |
||
| 181 | } |
||
| 182 | $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $iiifwrap['all.']); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | $output .= $this->templateService->substituteMarkerArray($subpart['block'], $markerArray); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } else { |
||
| 189 | $metaList = $this->getMetadataFromDatabase($metaList); |
||
| 190 | $collList = $this->getCollections(); |
||
| 191 | // Parse the metadata arrays. |
||
| 192 | foreach ($metadataArray as $metadata) { |
||
| 193 | $markerArray['###METADATA###'] = ''; |
||
| 194 | // Reset content object's data array. |
||
| 195 | $this->cObj->data = $cObjData; |
||
| 196 | // Load all the metadata values into the content object's data array. |
||
| 197 | foreach ($metadata as $index_name => $value) { |
||
| 198 | if (is_array($value)) { |
||
| 199 | $this->cObj->data[$index_name] = implode($this->conf['separator'], $value); |
||
| 200 | } else { |
||
| 201 | $this->cObj->data[$index_name] = $value; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | // Process each metadate. |
||
| 205 | foreach ($metaList as $index_name => $metaConf) { |
||
| 206 | $parsedValue = ''; |
||
| 207 | $fieldwrap = $this->parseTS($metaConf['wrap']); |
||
| 208 | do { |
||
| 209 | $value = @array_shift($metadata[$index_name]); |
||
| 210 | if ($index_name == 'title') { |
||
| 211 | // Get title of parent document if needed. |
||
| 212 | if (empty($value) && $this->conf['getTitle'] && $this->doc->parentId) { |
||
| 213 | $superiorTitle = Document::getTitle($this->doc->parentId, true); |
||
| 214 | if (!empty($superiorTitle)) { |
||
| 215 | $value = '[' . $superiorTitle . ']'; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | if (!empty($value)) { |
||
| 219 | $value = htmlspecialchars($value); |
||
| 220 | // Link title to pageview. |
||
| 221 | if ($this->conf['linkTitle'] && $metadata['_id']) { |
||
| 222 | $details = $this->doc->getLogicalStructure($metadata['_id']); |
||
| 223 | $value = $this->pi_linkTP($value, [$this->prefixId => ['id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points']) : 1)]], true, $this->conf['targetPid']); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 227 | // Translate name of holding library. |
||
| 228 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->conf['pages'])); |
||
| 229 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 230 | // Translate document type. |
||
| 231 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->conf['pages'])); |
||
| 232 | } elseif ($index_name == 'collection' && !empty($value)) { |
||
| 233 | // Check if collections isn't hidden. |
||
| 234 | if (in_array($value, $collList)) { |
||
| 235 | // Translate collection. |
||
| 236 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_collections', $this->conf['pages'])); |
||
| 237 | } else { |
||
| 238 | $value = ''; |
||
| 239 | } |
||
| 240 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 241 | // Translate ISO 639 language code. |
||
| 242 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
| 243 | } elseif (!empty($value)) { |
||
| 244 | // Sanitize value for output. |
||
| 245 | $value = htmlspecialchars($value); |
||
| 246 | } |
||
| 247 | // Hook for getting a customized value (requested by SBB). |
||
| 248 | foreach ($this->hookObjects as $hookObj) { |
||
| 249 | if (method_exists($hookObj, 'printMetadata_customizeMetadata')) { |
||
| 250 | $hookObj->printMetadata_customizeMetadata($value); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | // $value might be empty for aggregation metadata fields including other "hidden" fields. |
||
| 254 | $value = $this->cObj->stdWrap($value, $fieldwrap['value.']); |
||
| 255 | if (!empty($value)) { |
||
| 256 | $parsedValue .= $value; |
||
| 257 | } |
||
| 258 | } while (is_array($metadata[$index_name]) && count($metadata[$index_name]) > 0); |
||
| 259 | |||
| 260 | if (!empty($parsedValue)) { |
||
| 261 | $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']); |
||
| 262 | $field .= $parsedValue; |
||
| 263 | $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']); |
||
| 264 | } |
||
| 265 | } |
||
| 266 | $output .= $this->templateService->substituteMarkerArray($subpart['block'], $markerArray); |
||
| 267 | } |
||
| 268 | } |
||
| 269 | return $this->templateService->substituteSubpart($this->template, '###BLOCK###', $output, true); |
||
| 270 | } |
||
| 404 |