We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 38 |
| Paths | 111 |
| Total Lines | 101 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 128 | protected function printMetadata(array $metadata, $useOriginalIiifManifestMetadata = false) |
||
| 129 | { |
||
| 130 | if ($useOriginalIiifManifestMetadata) { |
||
| 131 | $iiifData = $this->buildIiifData($metadata); |
||
| 132 | $this->view->assign('useIiif', true); |
||
| 133 | $this->view->assign('iiifData', $iiifData); |
||
| 134 | } else { |
||
| 135 | // findBySettings also sorts entries by the `sorting` field |
||
| 136 | $metadataResult = $this->metadataRepository->findBySettings([ |
||
| 137 | 'is_listed' => !$this->settings['showFull'], |
||
| 138 | ]); |
||
| 139 | |||
| 140 | // Collect raw metadata into an array that will be passed as data to cObj. |
||
| 141 | // This lets metadata wraps reference (own or foreign) values via TypoScript "field". |
||
| 142 | $metaCObjData = []; |
||
| 143 | |||
| 144 | $buildUrl = []; |
||
| 145 | $externalUrl = []; |
||
| 146 | $i = 0; |
||
| 147 | foreach ($metadata as $section) { |
||
| 148 | $metaCObjData[$i] = []; |
||
| 149 | |||
| 150 | foreach ($section as $name => $value) { |
||
| 151 | // NOTE: Labels are to be escaped in Fluid template |
||
| 152 | |||
| 153 | $metaCObjData[$i][$name] = is_array($value) |
||
| 154 | ? implode($this->settings['separator'], $value) |
||
| 155 | : $value; |
||
| 156 | |||
| 157 | if ($name == 'title') { |
||
| 158 | // Get title of parent document if needed. |
||
| 159 | if (empty(implode('', $value)) && $this->settings['getTitle'] && $this->document->getPartof()) { |
||
| 160 | $superiorTitle = Doc::getTitle($this->document->getPartof(), true); |
||
| 161 | if (!empty($superiorTitle)) { |
||
| 162 | $metadata[$i][$name] = ['[' . $superiorTitle . ']']; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | if (!empty($value)) { |
||
| 166 | $metadata[$i][$name][0] = $metadata[$i][$name][0]; |
||
| 167 | // Link title to pageview. |
||
| 168 | if ($this->settings['linkTitle'] && $section['_id']) { |
||
| 169 | $details = $this->doc->getLogicalStructure($section['_id']); |
||
| 170 | $buildUrl[$i][$name]['buildUrl'] = [ |
||
| 171 | 'id' => $this->document->getUid(), |
||
| 172 | 'page' => (!empty($details['points']) ? intval($details['points']) : 1), |
||
| 173 | 'targetPid' => (!empty($this->settings['targetPid']) ? $this->settings['targetPid'] : 0), |
||
| 174 | ]; |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } elseif (($name == 'author' || $name == 'holder') && !empty($value) && !empty($value[0]['url'])) { |
||
| 178 | $externalUrl[$i][$name]['externalUrl'] = $value[0]; |
||
| 179 | } elseif (($name == 'geonames' || $name == 'wikidata' || $name == 'wikipedia') && !empty($value)) { |
||
| 180 | $externalUrl[$i][$name]['externalUrl'] = [ |
||
| 181 | 'name' => $value[0], |
||
| 182 | 'url' => $value[0] |
||
| 183 | ]; |
||
| 184 | } elseif ($name == 'owner' && empty($value)) { |
||
| 185 | // no owner is found by metadata records --> take the one associated to the document |
||
| 186 | $library = $this->document->getOwner(); |
||
| 187 | if ($library) { |
||
| 188 | $metadata[$i][$name][0] = $library->getLabel(); |
||
| 189 | } |
||
| 190 | } elseif ($name == 'type' && !empty($value)) { |
||
| 191 | // Translate document type. |
||
| 192 | $structure = $this->structureRepository->findOneByIndexName($metadata[$i][$name][0]); |
||
| 193 | if ($structure) { |
||
| 194 | $metadata[$i][$name][0] = $structure->getLabel(); |
||
| 195 | } |
||
| 196 | } elseif ($name == 'collection' && !empty($value)) { |
||
| 197 | // Check if collections isn't hidden. |
||
| 198 | $j = 0; |
||
| 199 | foreach ($value as $entry) { |
||
| 200 | $collection = $this->collectionRepository->findOneByIndexName($entry); |
||
| 201 | if ($collection) { |
||
| 202 | $metadata[$i][$name][$j] = $collection->getLabel() ? : ''; |
||
| 203 | $j++; |
||
| 204 | } |
||
| 205 | } |
||
| 206 | } elseif ($name == 'language' && !empty($value)) { |
||
| 207 | // Translate ISO 639 language code. |
||
| 208 | foreach ($metadata[$i][$name] as &$langValue) { |
||
| 209 | $langValue = Helper::getLanguageName($langValue); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | if (is_array($metadata[$i][$name])) { |
||
| 214 | $metadata[$i][$name] = array_values(array_filter($metadata[$i][$name], function($metadataValue) |
||
| 215 | { |
||
| 216 | return !empty($metadataValue); |
||
| 217 | })); |
||
| 218 | } |
||
| 219 | } |
||
| 220 | $i++; |
||
| 221 | } |
||
| 222 | |||
| 223 | $this->view->assign('buildUrl', $buildUrl); |
||
| 224 | $this->view->assign('externalUrl', $externalUrl); |
||
| 225 | $this->view->assign('documentMetadataSections', $metadata); |
||
| 226 | $this->view->assign('configMetadata', $metadataResult); |
||
| 227 | $this->view->assign('separator', $this->settings['separator']); |
||
| 228 | $this->view->assign('metaCObjData', $metaCObjData); |
||
| 229 | } |
||
| 378 |