We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 73 |
| Total Lines | 412 |
| 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 |
||
| 34 | class ListViewController extends AbstractController |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * This holds the field wrap of the metadata |
||
| 38 | * |
||
| 39 | * @var array |
||
| 40 | * @access private |
||
| 41 | */ |
||
| 42 | private $fieldwrap = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * This holds the list |
||
| 46 | * |
||
| 47 | * @var \Kitodo\Dlf\Common\DocumentList |
||
| 48 | * @access protected |
||
| 49 | */ |
||
| 50 | protected $list; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Array of sorted metadata |
||
| 54 | * |
||
| 55 | * @var array |
||
| 56 | * @access protected |
||
| 57 | */ |
||
| 58 | protected $metadata = []; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Array of sortable metadata |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | * @access protected |
||
| 65 | */ |
||
| 66 | protected $sortables = []; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Enriched documentList data for the view. |
||
| 70 | * |
||
| 71 | * @var array |
||
| 72 | */ |
||
| 73 | protected $metadataList = []; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Renders one entry of the list |
||
| 77 | * |
||
| 78 | * @access protected |
||
| 79 | * |
||
| 80 | * @param int $number: The number of the entry |
||
| 81 | * |
||
| 82 | * @return string The rendered entry ready for output |
||
| 83 | */ |
||
| 84 | protected function getEntry($number) |
||
| 85 | { |
||
| 86 | $imgAlt = ''; |
||
| 87 | $metadata = $this->list[$number]['metadata']; |
||
| 88 | foreach ($this->metadata as $index_name => $metaConf) { |
||
| 89 | if (!empty($metadata[$index_name])) { |
||
| 90 | $parsedValues = []; |
||
| 91 | $fieldwrap = $this->getFieldWrap($index_name, $metaConf['wrap']); |
||
| 92 | |||
| 93 | do { |
||
| 94 | $value = @array_shift($metadata[$index_name]); |
||
| 95 | // Link title to pageview. |
||
| 96 | if ($index_name == 'title') { |
||
| 97 | // Get title of parent document if needed. |
||
| 98 | if (empty($value) && $this->settings['getTitle']) { |
||
| 99 | $superiorTitle = Document::getTitle($this->list[$number]['uid'], true); |
||
| 100 | if (!empty($superiorTitle)) { |
||
| 101 | $value = '[' . $superiorTitle . ']'; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | // Set fake title if still not present. |
||
| 105 | if (empty($value)) { |
||
| 106 | $value = LocalizationUtility::translate('noTitle', 'dlf'); |
||
| 107 | } |
||
| 108 | $imgAlt = htmlspecialchars($value); |
||
| 109 | $value = htmlspecialchars($value); |
||
| 110 | |||
| 111 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 112 | // Translate name of holding library. |
||
| 113 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->settings['pages'])); |
||
| 114 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 115 | // Translate document type. |
||
| 116 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->settings['pages'])); |
||
| 117 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 118 | // Translate ISO 639 language code. |
||
| 119 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
| 120 | } elseif (!empty($value)) { |
||
| 121 | $value = htmlspecialchars($value); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (!empty($value)) { |
||
| 125 | $parsedValues[] = [ |
||
| 126 | 'value' => $value, |
||
| 127 | 'wrap' => $fieldwrap['value.'] |
||
| 128 | ]; |
||
| 129 | } |
||
| 130 | } while (count($metadata[$index_name])); |
||
| 131 | |||
| 132 | if (!empty($parsedValues)) { |
||
| 133 | $field[$index_name] = [ |
||
| 134 | 'label' => [ |
||
| 135 | 'value' => htmlspecialchars($metaConf['label']), |
||
| 136 | 'wrap' => $fieldwrap['key.'], |
||
| 137 | ], |
||
| 138 | 'values' => $parsedValues, |
||
| 139 | 'wrap' => $fieldwrap['all.'] |
||
| 140 | ]; |
||
| 141 | |||
| 142 | $this->metadataList[$number]['metadata'] = $field; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | // Add thumbnail. |
||
| 148 | if (!empty($this->list[$number]['thumbnail'])) { |
||
| 149 | $this->metadataList[$number]['thumbnail'] = [ |
||
| 150 | 'alt' => $imgAlt, |
||
| 151 | 'src' => $this->list[$number]['thumbnail'] |
||
| 152 | ]; |
||
| 153 | } |
||
| 154 | |||
| 155 | if (!empty($this->list[$number]['subparts'])) { |
||
| 156 | $this->getSubEntries($number); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Returns the parsed fieldwrap of a metadata |
||
| 162 | * |
||
| 163 | * @access private |
||
| 164 | * |
||
| 165 | * @param string $index_name: The index name of a metadata |
||
| 166 | * @param string $wrap: The configured metadata wrap |
||
| 167 | * |
||
| 168 | * @return array The parsed fieldwrap |
||
| 169 | */ |
||
| 170 | private function getFieldWrap($index_name, $wrap) |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Parses a string into a Typoscript array |
||
| 181 | * |
||
| 182 | * @access protected |
||
| 183 | * |
||
| 184 | * @param string $string: The string to parse |
||
| 185 | * |
||
| 186 | * @return array The resulting typoscript array |
||
| 187 | */ |
||
| 188 | protected function parseTS($string = '') |
||
| 189 | { |
||
| 190 | $parser = GeneralUtility::makeInstance(TypoScriptParser::class); |
||
| 191 | $parser->parse($string); |
||
| 192 | return $parser->setup; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Renders all sub-entries of one entry |
||
| 197 | * |
||
| 198 | * @access protected |
||
| 199 | * |
||
| 200 | * @param int $number: The number of the entry |
||
| 201 | * |
||
| 202 | * @return string The rendered entries ready for output |
||
| 203 | */ |
||
| 204 | protected function getSubEntries($number) |
||
| 205 | { |
||
| 206 | foreach ($this->list[$number]['subparts'] as $subpartKey => $subpart) { |
||
| 207 | $imgAlt = ''; |
||
| 208 | foreach ($this->metadata as $index_name => $metaConf) { |
||
| 209 | $parsedValues = []; |
||
| 210 | $fieldwrap = $this->getFieldWrap($index_name, $metaConf['wrap']); |
||
| 211 | do { |
||
| 212 | $value = @array_shift($subpart['metadata'][$index_name]); |
||
| 213 | // Link title to pageview. |
||
| 214 | if ($index_name == 'title') { |
||
| 215 | // Get title of parent document if needed. |
||
| 216 | if (empty($value) && $this->settings['getTitle']) { |
||
| 217 | $superiorTitle = Document::getTitle($subpart['uid'], true); |
||
| 218 | if (!empty($superiorTitle)) { |
||
| 219 | $value = '[' . $superiorTitle . ']'; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | // Set fake title if still not present. |
||
| 223 | if (empty($value)) { |
||
| 224 | $value = LocalizationUtility::translate('noTitle', 'dlf'); |
||
| 225 | } |
||
| 226 | $imgAlt = htmlspecialchars($value); |
||
| 227 | $value = htmlspecialchars($value); |
||
| 228 | } elseif ($index_name == 'owner' && !empty($value)) { |
||
| 229 | // Translate name of holding library. |
||
| 230 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->settings['pages'])); |
||
| 231 | } elseif ($index_name == 'type' && !empty($value)) { |
||
| 232 | // Translate document type. |
||
| 233 | $_value = $value; |
||
| 234 | $value = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->settings['pages'])); |
||
| 235 | // Add page number for single pages. |
||
| 236 | if ($_value == 'page') { |
||
| 237 | $value .= ' ' . intval($subpart['page']); |
||
| 238 | } |
||
| 239 | } elseif ($index_name == 'language' && !empty($value)) { |
||
| 240 | // Translate ISO 639 language code. |
||
| 241 | $value = htmlspecialchars(Helper::getLanguageName($value)); |
||
| 242 | } elseif (!empty($value)) { |
||
| 243 | $value = htmlspecialchars($value); |
||
| 244 | } |
||
| 245 | |||
| 246 | if (!empty($value)) { |
||
| 247 | $parsedValues[] = [ |
||
| 248 | 'value' => $value, |
||
| 249 | 'wrap' => $fieldwrap['value.'] |
||
| 250 | ]; |
||
| 251 | } |
||
| 252 | |||
| 253 | } while (is_array($subpart['metadata'][$index_name]) && count($subpart['metadata'][$index_name]) > 0); |
||
| 254 | if (!empty($parsedValues)) { |
||
| 255 | $field[$index_name] = [ |
||
| 256 | 'label' => [ |
||
| 257 | 'value' => htmlspecialchars($metaConf['label']), |
||
| 258 | 'wrap' => $fieldwrap['key.'], |
||
| 259 | ], |
||
| 260 | 'values' => $parsedValues, |
||
| 261 | 'wrap' => $fieldwrap['all.'] |
||
| 262 | ]; |
||
| 263 | |||
| 264 | $this->metadataList[$number]['subparts'][$subpartKey]['metadata'] = $field; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | // Add thumbnail. |
||
| 269 | if (!empty($subpart['thumbnail'])) { |
||
| 270 | $this->metadataList[$number]['subparts'][$subpartKey]['thumbnail'] = [ |
||
| 271 | 'alt' => $imgAlt, |
||
| 272 | 'src' => $subpart['thumbnail'] |
||
| 273 | ]; |
||
| 274 | } |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Get metadata configuration from database |
||
| 280 | * |
||
| 281 | * @access protected |
||
| 282 | * |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | protected function loadConfig() |
||
| 318 | } |
||
| 319 | } |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * The main method of the plugin |
||
| 324 | * |
||
| 325 | * @return void |
||
| 326 | */ |
||
| 327 | public function mainAction() |
||
| 448 |
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.