We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 40 |
| Paths | 56 |
| Total Lines | 127 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 1 | 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 |
||
| 197 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
| 198 | { |
||
| 199 | if ($useOriginalIiifManifestMetadata) { |
||
| 200 | $iiifData = []; |
||
| 201 | foreach ($metadataArray as $metadata) { |
||
| 202 | foreach ($metadata as $key => $group) { |
||
| 203 | if ($key == '_id') { |
||
| 204 | continue; |
||
| 205 | } |
||
| 206 | if (!is_array($group)) { |
||
| 207 | if ( |
||
| 208 | IRI::isAbsoluteIri($group) |
||
| 209 | && (($scheme = (new IRI($group))->getScheme()) == 'http' || $scheme == 'https') |
||
| 210 | ) { |
||
| 211 | // Build link |
||
| 212 | $iiifData[$key] = [ |
||
| 213 | 'label' => $key, |
||
| 214 | 'value' => $group, |
||
| 215 | 'buildUrl' => true, |
||
| 216 | ]; |
||
| 217 | } else { |
||
| 218 | // Data output |
||
| 219 | $iiifData[$key] = [ |
||
| 220 | 'label' => $key, |
||
| 221 | 'value' => $group, |
||
| 222 | 'buildUrl' => false, |
||
| 223 | ]; |
||
| 224 | } |
||
| 225 | } else { |
||
| 226 | foreach ($group as $label => $value) { |
||
| 227 | if ($label == '_id') { |
||
| 228 | continue; |
||
| 229 | } |
||
| 230 | if (is_array($value)) { |
||
| 231 | $value = implode($this->settings['separator'], $value); |
||
| 232 | } |
||
| 233 | // NOTE: Labels are to be escaped in Fluid template |
||
| 234 | if (IRI::isAbsoluteIri($value) && (($scheme = (new IRI($value))->getScheme()) == 'http' || $scheme == 'https')) { |
||
| 235 | $nolabel = $value == $label; |
||
| 236 | $iiifData[$key]['data'][] = [ |
||
| 237 | 'label' => $nolabel ? '' : $label, |
||
| 238 | 'value' => $value, |
||
| 239 | 'buildUrl' => true, |
||
| 240 | ]; |
||
| 241 | } else { |
||
| 242 | $iiifData[$key]['data'][] = [ |
||
| 243 | 'label' => $label, |
||
| 244 | 'value' => $value, |
||
| 245 | 'buildUrl' => false, |
||
| 246 | ]; |
||
| 247 | } |
||
| 248 | } |
||
| 249 | } |
||
| 250 | $this->view->assign('useIiif', true); |
||
| 251 | $this->view->assign('iiifData', $iiifData); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | } else { |
||
| 255 | |||
| 256 | // findBySettings also sorts entries by the `sorting` field |
||
| 257 | $metadataResult = $this->metadataRepository->findBySettings([ |
||
| 258 | 'is_listed' => !$this->settings['showFull'], |
||
| 259 | ]); |
||
| 260 | |||
| 261 | $buildUrl = []; |
||
| 262 | $i = 0; |
||
| 263 | foreach ($metadataArray as $metadataSection) { |
||
| 264 | foreach ($metadataSection as $metadataName => $metadataValue) { |
||
| 265 | // NOTE: Labels are to be escaped in Fluid template |
||
| 266 | |||
| 267 | if ($metadataName == 'title') { |
||
| 268 | // Get title of parent document if needed. |
||
| 269 | if (empty($metadataValue) && $this->settings['getTitle'] && $this->document->getDoc()->parentId) { |
||
| 270 | $superiorTitle = Doc::getTitle($this->document->getPartof(), true); |
||
| 271 | if (!empty($superiorTitle)) { |
||
| 272 | $metadataArray[$i][$metadataName] = ['[' . $superiorTitle . ']']; |
||
| 273 | } |
||
| 274 | } |
||
| 275 | if (!empty($metadataValue)) { |
||
| 276 | $metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
||
| 277 | // Link title to pageview. |
||
| 278 | if ($this->settings['linkTitle'] && $metadataSection['_id']) { |
||
| 279 | $details = $this->document->getDoc()->getLogicalStructure($metadataSection['_id']); |
||
| 280 | $buildUrl[$i][$metadataName]['buildUrl'] = [ |
||
| 281 | 'id' => $this->document->getUid(), |
||
| 282 | 'page' => (!empty($details['points']) ? intval($details['points']) : 1), |
||
| 283 | 'targetPid' => (!empty($this->settings['targetPid']) ? $this->settings['targetPid'] : 0), |
||
| 284 | ]; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | } elseif ($metadataName == 'owner' && !empty($metadataValue)) { |
||
| 288 | // Translate name of holding library. |
||
| 289 | $library = $this->libraryRepository->findOneByIndexName($metadataArray[$i][$metadataName][0]); |
||
| 290 | $metadataArray[$i][$metadataName][0] = $library->getLabel(); |
||
| 291 | } elseif ($metadataName == 'type' && !empty($metadataValue)) { |
||
| 292 | // Translate document type. |
||
| 293 | $structure = $this->structureRepository->findOneByIndexName($metadataArray[$i][$metadataName][0]); |
||
| 294 | $metadataArray[$i][$metadataName][0] = $structure->getLabel(); |
||
| 295 | } elseif ($metadataName == 'collection' && !empty($metadataValue)) { |
||
| 296 | // Check if collections isn't hidden. |
||
| 297 | $j = 0; |
||
| 298 | foreach ($metadataValue as $metadataEntry) { |
||
| 299 | $collection = $this->collectionRepository->findOneByIndexName($metadataEntry); |
||
| 300 | $metadataArray[$i][$metadataName][$j] = $collection->getLabel() ? : ''; |
||
| 301 | $j++; |
||
| 302 | } |
||
| 303 | } elseif ($metadataName == 'language' && !empty($metadataValue)) { |
||
| 304 | // Translate ISO 639 language code. |
||
| 305 | $metadataArray[$i][$metadataName][0] = Helper::getLanguageName($metadataArray[$i][$metadataName][0]); |
||
| 306 | } elseif (!empty($metadataValue)) { |
||
| 307 | $metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
||
| 308 | } |
||
| 309 | |||
| 310 | if (is_array($metadataArray[$i][$metadataName])) { |
||
| 311 | $metadataArray[$i][$metadataName] = array_values(array_filter($metadataArray[$i][$metadataName], function($value) |
||
| 312 | { |
||
| 313 | return !empty($value); |
||
| 314 | })); |
||
| 315 | } |
||
| 316 | } |
||
| 317 | $i++; |
||
| 318 | } |
||
| 319 | |||
| 320 | $this->view->assign('buildUrl', $buildUrl); |
||
| 321 | $this->view->assign('documentMetadataSections', $metadataArray); |
||
| 322 | $this->view->assign('configMetadata', $metadataResult); |
||
| 323 | $this->view->assign('separator', $this->settings['separator']); |
||
| 324 | |||
| 328 |