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