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