We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 74 |
| Total Lines | 403 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ListViewController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ListViewController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class ListViewController extends AbstractController |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * This holds the field wrap of the metadata |
||
| 39 | * |
||
| 40 | * @var array |
||
| 41 | * @access private |
||
| 42 | */ |
||
| 43 | private $fieldwrap = []; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * This holds the list |
||
| 47 | * |
||
| 48 | * @var \Kitodo\Dlf\Common\DocumentList |
||
| 49 | * @access protected |
||
| 50 | */ |
||
| 51 | protected $list; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Array of sorted metadata |
||
| 55 | * |
||
| 56 | * @var array |
||
| 57 | * @access protected |
||
| 58 | */ |
||
| 59 | protected $metadata = []; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Array of sortable metadata |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | * @access protected |
||
| 66 | */ |
||
| 67 | protected $sortables = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Enriched documentList data for the view. |
||
| 71 | * |
||
| 72 | * @var array |
||
| 73 | */ |
||
| 74 | protected $metadataList = []; |
||
| 75 | |||
| 76 | protected $metadataRepository; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param MetadataRepository $metadataRepository |
||
| 80 | */ |
||
| 81 | public function injectMetadataRepository(MetadataRepository $metadataRepository) |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Renders one entry of the list |
||
| 88 | * |
||
| 89 | * @access protected |
||
| 90 | * |
||
| 91 | * @param int $number: The number of the entry |
||
| 92 | * |
||
| 93 | * @return string The rendered entry ready for output |
||
| 94 | */ |
||
| 95 | protected function getEntry($number) |
||
| 96 | { |
||
| 97 | $imgAlt = ''; |
||
| 98 | $metadata = $this->list[$number]['metadata']; |
||
| 99 | foreach ($this->metadata as $index_name => $metaConf) { |
||
| 100 | if (!empty($metadata[$index_name])) { |
||
| 101 | $parsedValues = []; |
||
| 102 | $fieldwrap = $this->getFieldWrap($index_name, $metaConf['wrap']); |
||
| 103 | |||
| 104 | do { |
||
| 105 | $value = @array_shift($metadata[$index_name]); |
||
| 106 | // Link title to pageview. |
||
| 107 | if ($index_name == 'title') { |
||
| 108 | // Get title of parent document if needed. |
||
| 109 | if (empty($value) && $this->settings['getTitle']) { |
||
| 110 | $superiorTitle = Document::getTitle($this->list[$number]['uid'], true); |
||
| 111 | if (!empty($superiorTitle)) { |
||
| 112 | $value = '[' . $superiorTitle . ']'; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | // Set fake title if still not present. |
||
| 116 | if (empty($value)) { |
||
| 117 | $value = LocalizationUtility::translate('noTitle', 'dlf'); |
||
| 118 | } |
||
| 119 | $imgAlt = htmlspecialchars($value); |
||
| 120 | $value = htmlspecialchars($value); |
||
| 121 | |||
| 122 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 123 | // Translate name of holding library. |
||
| 124 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->settings['pages'])); |
||
| 125 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 126 | // Translate document type. |
||
| 127 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->settings['pages'])); |
||
| 128 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 129 | // Translate ISO 639 language code. |
||
| 130 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
| 131 | } elseif (!empty($value)) { |
||
| 132 | $value = htmlspecialchars($value); |
||
| 133 | } |
||
| 134 | |||
| 135 | if (!empty($value)) { |
||
| 136 | $parsedValues[] = [ |
||
| 137 | 'value' => $value, |
||
| 138 | 'wrap' => $fieldwrap['value.'] |
||
| 139 | ]; |
||
| 140 | } |
||
| 141 | } while (count($metadata[$index_name])); |
||
| 142 | |||
| 143 | if (!empty($parsedValues)) { |
||
| 144 | $field[$index_name] = [ |
||
| 145 | 'label' => [ |
||
| 146 | 'value' => htmlspecialchars($metaConf['label']), |
||
| 147 | 'wrap' => $fieldwrap['key.'], |
||
| 148 | ], |
||
| 149 | 'values' => $parsedValues, |
||
| 150 | 'wrap' => $fieldwrap['all.'] |
||
| 151 | ]; |
||
| 152 | |||
| 153 | $this->metadataList[$number]['metadata'] = $field; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | // Add thumbnail. |
||
| 159 | if (!empty($this->list[$number]['thumbnail'])) { |
||
| 160 | $this->metadataList[$number]['thumbnail'] = [ |
||
| 161 | 'alt' => $imgAlt, |
||
| 162 | 'src' => $this->list[$number]['thumbnail'] |
||
| 163 | ]; |
||
| 164 | } |
||
| 165 | |||
| 166 | if (!empty($this->list[$number]['subparts'])) { |
||
| 167 | $this->getSubEntries($number); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Returns the parsed fieldwrap of a metadata |
||
| 173 | * |
||
| 174 | * @access private |
||
| 175 | * |
||
| 176 | * @param string $index_name: The index name of a metadata |
||
| 177 | * @param string $wrap: The configured metadata wrap |
||
| 178 | * |
||
| 179 | * @return array The parsed fieldwrap |
||
| 180 | */ |
||
| 181 | private function getFieldWrap($index_name, $wrap) |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Parses a string into a Typoscript array |
||
| 192 | * |
||
| 193 | * @access protected |
||
| 194 | * |
||
| 195 | * @param string $string: The string to parse |
||
| 196 | * |
||
| 197 | * @return array The resulting typoscript array |
||
| 198 | */ |
||
| 199 | protected function parseTS($string = '') |
||
| 200 | { |
||
| 201 | $parser = GeneralUtility::makeInstance(TypoScriptParser::class); |
||
| 202 | $parser->parse($string); |
||
| 203 | return $parser->setup; |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Renders all sub-entries of one entry |
||
| 208 | * |
||
| 209 | * @access protected |
||
| 210 | * |
||
| 211 | * @param int $number: The number of the entry |
||
| 212 | * |
||
| 213 | * @return string The rendered entries ready for output |
||
| 214 | */ |
||
| 215 | protected function getSubEntries($number) |
||
| 216 | { |
||
| 217 | foreach ($this->list[$number]['subparts'] as $subpartKey => $subpart) { |
||
| 218 | $imgAlt = ''; |
||
| 219 | foreach ($this->metadata as $index_name => $metaConf) { |
||
| 220 | $parsedValues = []; |
||
| 221 | $fieldwrap = $this->getFieldWrap($index_name, $metaConf['wrap']); |
||
| 222 | do { |
||
| 223 | $value = @array_shift($subpart['metadata'][$index_name]); |
||
| 224 | // Link title to pageview. |
||
| 225 | if ($index_name == 'title') { |
||
| 226 | // Get title of parent document if needed. |
||
| 227 | if (empty($value) && $this->settings['getTitle']) { |
||
| 228 | $superiorTitle = Document::getTitle($subpart['uid'], true); |
||
| 229 | if (!empty($superiorTitle)) { |
||
| 230 | $value = '[' . $superiorTitle . ']'; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | // Set fake title if still not present. |
||
| 234 | if (empty($value)) { |
||
| 235 | $value = LocalizationUtility::translate('noTitle', 'dlf'); |
||
| 236 | } |
||
| 237 | $imgAlt = htmlspecialchars($value); |
||
| 238 | $value = htmlspecialchars($value); |
||
| 239 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 240 | // Translate name of holding library. |
||
| 241 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->settings['pages'])); |
||
| 242 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 243 | // Translate document type. |
||
| 244 | $_value = $value; |
||
| 245 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->settings['pages'])); |
||
| 246 | // Add page number for single pages. |
||
| 247 | if ($_value == 'page') { |
||
| 248 | $value .= ' ' . intval($subpart['page']); |
||
| 249 | } |
||
| 250 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 251 | // Translate ISO 639 language code. |
||
| 252 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
| 253 | } elseif (!empty($value)) { |
||
| 254 | $value = htmlspecialchars($value); |
||
| 255 | } |
||
| 256 | |||
| 257 | if (!empty($value)) { |
||
| 258 | $parsedValues[] = [ |
||
| 259 | 'value' => $value, |
||
| 260 | 'wrap' => $fieldwrap['value.'] |
||
| 261 | ]; |
||
| 262 | } |
||
| 263 | |||
| 264 | } while (is_array($subpart['metadata'][$index_name]) && count($subpart['metadata'][$index_name]) > 0); |
||
| 265 | if (!empty($parsedValues)) { |
||
| 266 | $field[$index_name] = [ |
||
| 267 | 'label' => [ |
||
| 268 | 'value' => htmlspecialchars($metaConf['label']), |
||
| 269 | 'wrap' => $fieldwrap['key.'], |
||
| 270 | ], |
||
| 271 | 'values' => $parsedValues, |
||
| 272 | 'wrap' => $fieldwrap['all.'] |
||
| 273 | ]; |
||
| 274 | |||
| 275 | $this->metadataList[$number]['subparts'][$subpartKey]['metadata'] = $field; |
||
| 276 | } |
||
| 277 | } |
||
| 278 | |||
| 279 | // Add thumbnail. |
||
| 280 | if (!empty($subpart['thumbnail'])) { |
||
| 281 | $this->metadataList[$number]['subparts'][$subpartKey]['thumbnail'] = [ |
||
| 282 | 'alt' => $imgAlt, |
||
| 283 | 'src' => $subpart['thumbnail'] |
||
| 284 | ]; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Get metadata configuration from database |
||
| 291 | * |
||
| 292 | * @access protected |
||
| 293 | * |
||
| 294 | * @return void |
||
| 295 | */ |
||
| 296 | protected function loadConfig() |
||
| 310 | } |
||
| 311 | } |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * The main method of the plugin |
||
| 316 | * |
||
| 317 | * @return void |
||
| 318 | */ |
||
| 319 | public function mainAction() |
||
| 438 | } |
||
| 439 | } |
||
| 440 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.