We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 47 |
| Paths | 112 |
| Total Lines | 146 |
| Code Lines | 92 |
| 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 |
||
| 134 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
| 135 | { |
||
| 136 | if ($useOriginalIiifManifestMetadata) { |
||
| 137 | $iiifData = []; |
||
| 138 | foreach ($metadataArray as $metadata) { |
||
| 139 | foreach ($metadata as $key => $group) { |
||
| 140 | if ($key == '_id' || $key === '_active') { |
||
| 141 | continue; |
||
| 142 | } |
||
| 143 | if (!is_array($group)) { |
||
| 144 | if ( |
||
| 145 | IRI::isAbsoluteIri($group) |
||
| 146 | && (($scheme = (new IRI($group))->getScheme()) == 'http' || $scheme == 'https') |
||
| 147 | ) { |
||
| 148 | // Build link |
||
| 149 | $iiifData[$key] = [ |
||
| 150 | 'label' => $key, |
||
| 151 | 'value' => $group, |
||
| 152 | 'buildUrl' => true, |
||
| 153 | ]; |
||
| 154 | } else { |
||
| 155 | // Data output |
||
| 156 | $iiifData[$key] = [ |
||
| 157 | 'label' => $key, |
||
| 158 | 'value' => $group, |
||
| 159 | 'buildUrl' => false, |
||
| 160 | ]; |
||
| 161 | } |
||
| 162 | } else { |
||
| 163 | foreach ($group as $label => $value) { |
||
| 164 | if ($label === '_id' || $label === '_active') { |
||
| 165 | continue; |
||
| 166 | } |
||
| 167 | if (is_array($value)) { |
||
| 168 | $value = implode($this->settings['separator'], $value); |
||
| 169 | } |
||
| 170 | // NOTE: Labels are to be escaped in Fluid template |
||
| 171 | if (IRI::isAbsoluteIri($value) && (($scheme = (new IRI($value))->getScheme()) == 'http' || $scheme == 'https')) { |
||
| 172 | $nolabel = $value == $label; |
||
| 173 | $iiifData[$key]['data'][] = [ |
||
| 174 | 'label' => $nolabel ? '' : $label, |
||
| 175 | 'value' => $value, |
||
| 176 | 'buildUrl' => true, |
||
| 177 | ]; |
||
| 178 | } else { |
||
| 179 | $iiifData[$key]['data'][] = [ |
||
| 180 | 'label' => $label, |
||
| 181 | 'value' => $value, |
||
| 182 | 'buildUrl' => false, |
||
| 183 | ]; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | $this->view->assign('useIiif', true); |
||
| 188 | $this->view->assign('iiifData', $iiifData); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } else { |
||
| 192 | |||
| 193 | // findBySettings also sorts entries by the `sorting` field |
||
| 194 | $metadataResult = $this->metadataRepository->findBySettings([ |
||
| 195 | 'is_listed' => !$this->settings['showFull'], |
||
| 196 | ]); |
||
| 197 | |||
| 198 | // Collect raw metadata into an array that will be passed as data to cObj. |
||
| 199 | // This lets metadata wraps reference (own or foreign) values via TypoScript "field". |
||
| 200 | $metaCObjData = []; |
||
| 201 | |||
| 202 | $buildUrl = []; |
||
| 203 | $i = 0; |
||
| 204 | foreach ($metadataArray as $metadataSection) { |
||
| 205 | $metaCObjData[$i] = []; |
||
| 206 | |||
| 207 | foreach ($metadataSection as $metadataName => $metadataValue) { |
||
| 208 | // NOTE: Labels are to be escaped in Fluid template |
||
| 209 | |||
| 210 | $metaCObjData[$i][$metadataName] = is_array($metadataValue) |
||
| 211 | ? implode($this->settings['separator'], $metadataValue) |
||
| 212 | : $metadataValue; |
||
| 213 | |||
| 214 | if ($metadataName == 'title') { |
||
| 215 | // Get title of parent document if needed. |
||
| 216 | if (empty(implode('', $metadataValue)) && $this->settings['getTitle'] && $this->document->getPartof()) { |
||
| 217 | $superiorTitle = Doc::getTitle($this->document->getPartof(), true); |
||
| 218 | if (!empty($superiorTitle)) { |
||
| 219 | $metadataArray[$i][$metadataName] = ['[' . $superiorTitle . ']']; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | if (!empty($metadataValue)) { |
||
| 223 | $metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
||
| 224 | // Link title to pageview. |
||
| 225 | if ($this->settings['linkTitle'] && $metadataSection['_id']) { |
||
| 226 | $details = $this->document->getDoc()->getLogicalStructure($metadataSection['_id']); |
||
| 227 | $buildUrl[$i][$metadataName]['buildUrl'] = [ |
||
| 228 | 'id' => $this->document->getUid(), |
||
| 229 | 'page' => (!empty($details['points']) ? intval($details['points']) : 1), |
||
| 230 | 'targetPid' => (!empty($this->settings['targetPid']) ? $this->settings['targetPid'] : 0), |
||
| 231 | ]; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | } elseif ($metadataName == 'owner' && empty($metadataValue)) { |
||
| 235 | // no owner is found by metadata records --> take the one associated to the document |
||
| 236 | $library = $this->document->getOwner(); |
||
| 237 | if ($library) { |
||
| 238 | $metadataArray[$i][$metadataName][0] = $library->getLabel(); |
||
| 239 | } |
||
| 240 | } elseif ($metadataName == 'type' && !empty($metadataValue)) { |
||
| 241 | // Translate document type. |
||
| 242 | $structure = $this->structureRepository->findOneByIndexName($metadataArray[$i][$metadataName][0]); |
||
| 243 | if ($structure) { |
||
| 244 | $metadataArray[$i][$metadataName][0] = $structure->getLabel(); |
||
| 245 | } |
||
| 246 | } elseif ($metadataName == 'collection' && !empty($metadataValue)) { |
||
| 247 | // Check if collections isn't hidden. |
||
| 248 | $j = 0; |
||
| 249 | foreach ($metadataValue as $metadataEntry) { |
||
| 250 | $collection = $this->collectionRepository->findOneByIndexName($metadataEntry); |
||
| 251 | if ($collection) { |
||
| 252 | $metadataArray[$i][$metadataName][$j] = $collection->getLabel() ? : ''; |
||
| 253 | $j++; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | } elseif ($metadataName == 'language' && !empty($metadataValue)) { |
||
| 257 | // Translate ISO 639 language code. |
||
| 258 | foreach ($metadataArray[$i][$metadataName] as &$langValue) { |
||
| 259 | $langValue = Helper::getLanguageName($langValue); |
||
| 260 | } |
||
| 261 | } elseif (!empty($metadataValue)) { |
||
| 262 | $metadataArray[$i][$metadataName][0] = $metadataArray[$i][$metadataName][0]; |
||
| 263 | } |
||
| 264 | |||
| 265 | if (is_array($metadataArray[$i][$metadataName])) { |
||
| 266 | $metadataArray[$i][$metadataName] = array_values(array_filter($metadataArray[$i][$metadataName], function($value) |
||
| 267 | { |
||
| 268 | return !empty($value); |
||
| 269 | })); |
||
| 270 | } |
||
| 271 | } |
||
| 272 | $i++; |
||
| 273 | } |
||
| 274 | |||
| 275 | $this->view->assign('buildUrl', $buildUrl); |
||
| 276 | $this->view->assign('documentMetadataSections', $metadataArray); |
||
| 277 | $this->view->assign('configMetadata', $metadataResult); |
||
| 278 | $this->view->assign('separator', $this->settings['separator']); |
||
| 279 | $this->view->assign('metaCObjData', $metaCObjData); |
||
| 280 | } |
||
| 365 |