We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 40 |
| Paths | 58 |
| Total Lines | 126 |
| Code Lines | 82 |
| 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 |
||
| 158 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
| 159 | { |
||
| 160 | if ($useOriginalIiifManifestMetadata) { |
||
| 161 | $iiifData = []; |
||
| 162 | foreach ($metadataArray as $metadata) { |
||
| 163 | foreach ($metadata as $key => $group) { |
||
| 164 | if ($key == '_id') { |
||
| 165 | continue; |
||
| 166 | } |
||
| 167 | if (!is_array($group)) { |
||
| 168 | if ( |
||
| 169 | IRI::isAbsoluteIri($group) |
||
| 170 | && (($scheme = (new IRI($group))->getScheme()) == 'http' || $scheme == 'https') |
||
| 171 | ) { |
||
| 172 | // Build link |
||
| 173 | $iiifData[$key] = [ |
||
| 174 | 'label' => $key, |
||
| 175 | 'value' => $group, |
||
| 176 | 'buildUrl' => true |
||
| 177 | ]; |
||
| 178 | } else { |
||
| 179 | // Data output |
||
| 180 | $iiifData[$key] = [ |
||
| 181 | 'label' => $key, |
||
| 182 | 'value' => $group, |
||
| 183 | 'buildUrl' => false |
||
| 184 | ]; |
||
| 185 | } |
||
| 186 | } else { |
||
| 187 | foreach ($group as $label => $value) { |
||
| 188 | if ($label == '_id') { |
||
| 189 | continue; |
||
| 190 | } |
||
| 191 | if (is_array($value)) { |
||
| 192 | $value = implode($this->settings['separator'], $value); |
||
| 193 | } |
||
| 194 | if (IRI::isAbsoluteIri($value) && (($scheme = (new IRI($value))->getScheme()) == 'http' || $scheme == 'https')) { |
||
| 195 | $nolabel = $value == $label; |
||
| 196 | $iiifData[$key]['data'][] = [ |
||
| 197 | 'label' => $nolabel ? '' : htmlspecialchars($label), |
||
| 198 | 'value' => $value, |
||
| 199 | 'buildUrl' => true |
||
| 200 | ]; |
||
| 201 | } else { |
||
| 202 | $iiifData[$key]['data'][] = [ |
||
| 203 | 'label' => htmlspecialchars($label), |
||
| 204 | 'value' => $value, |
||
| 205 | 'buildUrl' => false |
||
| 206 | ]; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | $this->view->assign('useIiif', true); |
||
| 211 | $this->view->assign('iiifData', $iiifData); |
||
| 212 | } |
||
| 213 | } |
||
| 214 | } else { |
||
| 215 | |||
| 216 | $metadataResult = $this->metadataRepository->findAll(); |
||
| 217 | |||
| 218 | // Get collections to check if they are hidden |
||
| 219 | $collections = $this->collectionRepository->getCollectionForMetadata($this->settings['storagePid']); |
||
| 220 | |||
| 221 | $collList = []; |
||
| 222 | /** @var Collection $collection */ |
||
| 223 | foreach ($collections as $collection) { |
||
| 224 | $collList[] = $collection->getIndexName(); |
||
| 225 | } |
||
| 226 | |||
| 227 | $buildUrl = []; |
||
| 228 | $i = 0; |
||
| 229 | foreach ($metadataArray as $metadataSection) { |
||
| 230 | foreach ($metadataSection as $metadataName => $metadataValue) { |
||
| 231 | if ($metadataName == 'title') { |
||
| 232 | // Get title of parent document if needed. |
||
| 233 | if (empty($metadataValue) && $this->settings['getTitle'] && $this->document->getDoc()->parentId) { |
||
| 234 | $superiorTitle = Doc::getTitle($this->document->getPartof(), true); |
||
| 235 | if (!empty($superiorTitle)) { |
||
| 236 | $metadataArray[$i][$metadataName] = ['[' . $superiorTitle . ']']; |
||
| 237 | } |
||
| 238 | } |
||
| 239 | if (!empty($metadataValue)) { |
||
| 240 | $metadataArray[$i][$metadataName][0] = htmlspecialchars($metadataArray[$i][$metadataName][0]); |
||
| 241 | // Link title to pageview. |
||
| 242 | if ($this->settings['linkTitle'] && $metadataSection['_id']) { |
||
| 243 | $details = $this->document->getDoc()->getLogicalStructure($metadataSection['_id']); |
||
| 244 | $buildUrl[$i][$metadataName]['buildUrl'] = [ |
||
| 245 | 'id' => $this->document->getUid(), |
||
| 246 | 'page' => (!empty($details['points']) ? intval($details['points']) : 1), |
||
| 247 | 'targetPid' => (!empty($this->settings['targetPid']) ? $this->settings['targetPid'] : 0) |
||
| 248 | ]; |
||
| 249 | } |
||
| 250 | } |
||
| 251 | } elseif ($metadataName == 'owner' && !empty($metadataValue)) { |
||
| 252 | // Translate name of holding library. |
||
| 253 | $metadataArray[$i][$metadataName][0] = htmlspecialchars(Helper::translate($metadataArray[$i][$metadataName][0], 'tx_dlf_libraries', $this->settings['storagePid'])); |
||
| 254 | } elseif ($metadataName == 'type' && !empty($metadataValue)) { |
||
| 255 | // Translate document type. |
||
| 256 | $metadataArray[$i][$metadataName][0] = htmlspecialchars(Helper::translate($metadataArray[$i][$metadataName][0], 'tx_dlf_structures', $this->settings['storagePid'])); |
||
| 257 | } elseif ($metadataName == 'collection' && !empty($metadataValue)) { |
||
| 258 | // Check if collections isn't hidden. |
||
| 259 | $j = 0; |
||
| 260 | foreach ($metadataValue as $metadataEntry) { |
||
| 261 | if (in_array($metadataEntry, $collList)) { |
||
| 262 | // Translate collection. |
||
| 263 | $metadataArray[$i][$metadataName][$j] = htmlspecialchars(Helper::translate($metadataArray[$i][$metadataName][$j], 'tx_dlf_collections', $this->settings['storagePid'])); |
||
| 264 | } else { |
||
| 265 | $metadataArray[$i][$metadataName][$j] = ''; |
||
| 266 | } |
||
| 267 | $j++; |
||
| 268 | } |
||
| 269 | } elseif ($metadataName == 'language' && !empty($metadataValue)) { |
||
| 270 | // Translate ISO 639 language code. |
||
| 271 | $metadataArray[$i][$metadataName][0] = htmlspecialchars(Helper::getLanguageName($metadataArray[$i][$metadataName][0])); |
||
| 272 | } elseif (!empty($metadataValue)) { |
||
| 273 | // Sanitize value for output. |
||
| 274 | $metadataArray[$i][$metadataName][0] = htmlspecialchars($metadataArray[$i][$metadataName][0]); |
||
| 275 | } |
||
| 276 | } |
||
| 277 | $i++; |
||
| 278 | } |
||
| 279 | |||
| 280 | $this->view->assign('buildUrl', $buildUrl); |
||
| 281 | $this->view->assign('documentMetadataSections', $metadataArray); |
||
| 282 | $this->view->assign('configMetadata', $metadataResult); |
||
| 283 | $this->view->assign('separator', $this->settings['separator']); |
||
| 284 | |||
| 288 |