We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 38 |
| Paths | 8162 |
| Total Lines | 124 |
| Code Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 $metadataArray) { |
||
| 131 | // Load template file. |
||
| 132 | $this->getTemplate(); |
||
| 133 | $output = ''; |
||
| 134 | $subpart['block'] = $this->cObj->getSubpart($this->template, '###BLOCK###'); |
||
|
1 ignored issue
–
show
|
|||
| 135 | // Get list of metadata to show. |
||
| 136 | $metaList = []; |
||
| 137 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 138 | 'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.wrap AS wrap,tx_dlf_metadata.sys_language_uid AS sys_language_uid', |
||
| 139 | 'tx_dlf_metadata', |
||
| 140 | 'tx_dlf_metadata.pid='.intval($this->conf['pages']) |
||
| 141 | .' AND (sys_language_uid IN (-1,0) OR (sys_language_uid = '.$GLOBALS['TSFE']->sys_language_uid.' AND l18n_parent = 0))' |
||
| 142 | .Helper::whereClause('tx_dlf_metadata'), |
||
| 143 | '', |
||
| 144 | 'tx_dlf_metadata.sorting', |
||
| 145 | '' |
||
| 146 | ); |
||
| 147 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 148 | if (is_array($resArray) && $resArray['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) { |
||
| 149 | $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_metadata', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 150 | } |
||
| 151 | if ($resArray) { |
||
| 152 | if ($this->conf['showFull'] || $resArray['is_listed']) { |
||
| 153 | $metaList[$resArray['index_name']] = [ |
||
| 154 | 'wrap' => $resArray['wrap'], |
||
| 155 | 'label' => Helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages']) |
||
| 156 | ]; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 | // Get list of collections to show. |
||
| 161 | $collList = []; |
||
| 162 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 163 | 'tx_dlf_collections.index_name AS index_name', |
||
| 164 | 'tx_dlf_collections', |
||
| 165 | 'tx_dlf_collections.pid='.intval($this->conf['pages']) |
||
| 166 | .Helper::whereClause('tx_dlf_collections'), |
||
| 167 | '', |
||
| 168 | '', |
||
| 169 | '' |
||
| 170 | ); |
||
| 171 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 172 | $collList[] = $resArray['index_name']; |
||
| 173 | } |
||
| 174 | // Save original data array. |
||
| 175 | $cObjData = $this->cObj->data; |
||
| 176 | // Parse the metadata arrays. |
||
| 177 | foreach ($metadataArray as $metadata) { |
||
| 178 | $markerArray['###METADATA###'] = ''; |
||
| 179 | // Reset content object's data array. |
||
| 180 | $this->cObj->data = $cObjData; |
||
| 181 | // Load all the metadata values into the content object's data array. |
||
| 182 | foreach ($metadata as $index_name => $value) { |
||
| 183 | if (is_array($value)) { |
||
| 184 | $this->cObj->data[$index_name] = implode($this->conf['separator'], $value); |
||
| 185 | } else { |
||
| 186 | $this->cObj->data[$index_name] = $value; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | // Process each metadate. |
||
| 190 | foreach ($metaList as $index_name => $metaConf) { |
||
| 191 | if (!empty($metadata[$index_name])) { |
||
| 192 | $parsedValue = ''; |
||
| 193 | $fieldwrap = $this->parseTS($metaConf['wrap']); |
||
| 194 | do { |
||
| 195 | $value = @array_shift($metadata[$index_name]); |
||
| 196 | if ($index_name == 'title') { |
||
| 197 | // Get title of parent document if needed. |
||
| 198 | if (empty($value) && $this->conf['getTitle'] && $this->doc->parentId) { |
||
| 199 | $superiorTitle = Document::getTitle($this->doc->parentId, TRUE); |
||
| 200 | if (!empty($superiorTitle)) { |
||
| 201 | $value = '['.$superiorTitle.']'; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | if (!empty($value)) { |
||
| 205 | $value = htmlspecialchars($value); |
||
| 206 | // Link title to pageview. |
||
| 207 | if ($this->conf['linkTitle'] && $metadata['_id']) { |
||
| 208 | $details = $this->doc->getLogicalStructure($metadata['_id']); |
||
| 209 | $value = $this->pi_linkTP($value, [$this->prefixId => ['id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points']) : 1)]], TRUE, $this->conf['targetPid']); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 213 | // Translate name of holding library. |
||
| 214 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->conf['pages'])); |
||
| 215 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 216 | // Translate document type. |
||
| 217 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->conf['pages'])); |
||
| 218 | } elseif ($index_name == 'collection' && !empty($value)) { |
||
| 219 | // Check if collections isn't hidden. |
||
| 220 | if (in_array($value, $collList)) { |
||
| 221 | // Translate collection. |
||
| 222 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_collections', $this->conf['pages'])); |
||
| 223 | } else { |
||
| 224 | $value = ''; |
||
| 225 | } |
||
| 226 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 227 | // Translate ISO 639 language code. |
||
| 228 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
| 229 | } elseif (!empty($value)) { |
||
| 230 | // Sanitize value for output. |
||
| 231 | $value = htmlspecialchars($value); |
||
| 232 | } |
||
| 233 | // Hook for getting a customized value (requested by SBB). |
||
| 234 | foreach ($this->hookObjects as $hookObj) { |
||
| 235 | if (method_exists($hookObj, 'printMetadata_customizeMetadata')) { |
||
| 236 | $hookObj->printMetadata_customizeMetadata($value); |
||
| 237 | } |
||
| 238 | } |
||
| 239 | $value = $this->cObj->stdWrap($value, $fieldwrap['value.']); |
||
| 240 | if (!empty($value)) { |
||
| 241 | $parsedValue .= $value; |
||
| 242 | } |
||
| 243 | } while (count($metadata[$index_name])); |
||
| 244 | if (!empty($parsedValue)) { |
||
| 245 | $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']); |
||
| 246 | $field .= $parsedValue; |
||
| 247 | $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']); |
||
| 248 | } |
||
| 249 | } |
||
| 250 | } |
||
| 251 | $output .= $this->cObj->substituteMarkerArray($subpart['block'], $markerArray); |
||
| 252 | } |
||
| 253 | return $this->cObj->substituteSubpart($this->template, '###BLOCK###', $output, TRUE); |
||
| 254 | } |
||
| 256 |