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