We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 84 |
| Total Lines | 430 |
| Duplicated Lines | 0 % |
| Changes | 11 | ||
| Bugs | 1 | Features | 0 |
Complex classes like TableOfContentsController 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 TableOfContentsController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class TableOfContentsController extends AbstractController |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * This holds the active entries according to the currently selected page |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | * @access protected |
||
| 34 | */ |
||
| 35 | protected $activeEntries = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The main method of the plugin |
||
| 39 | * |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | public function mainAction() |
||
| 43 | { |
||
| 44 | // Load current document. |
||
| 45 | $this->loadDocument($this->requestData); |
||
| 46 | if ( |
||
| 47 | $this->document === null |
||
| 48 | || $this->document->getDoc() === null |
||
| 49 | ) { |
||
| 50 | // Quit without doing anything if required variables are not set. |
||
| 51 | return; |
||
| 52 | } else { |
||
| 53 | if (!empty($this->requestData['logicalPage'])) { |
||
| 54 | $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
||
| 55 | // The logical page parameter should not appear again |
||
| 56 | unset($this->requestData['logicalPage']); |
||
| 57 | } |
||
| 58 | if ($this->document->getDoc()->tableOfContents[0]['type'] == 'collection') { |
||
| 59 | $this->view->assign('currentList', $this->requestData['id']); |
||
| 60 | if (isset($this->requestData['transform'])) { |
||
| 61 | $this->view->assign('transform', $this->requestData['transform']); |
||
| 62 | } else { |
||
| 63 | $this->view->assign('transform', 'something'); |
||
| 64 | } |
||
| 65 | $this->view->assign('type', 'collection'); |
||
| 66 | $this->view->assign('types', $this->getTypes($this->document->getDoc()->tableOfContents)); |
||
| 67 | $this->view->assign('toc', $this->makeMenuFor3DObjects()); |
||
| 68 | } else { |
||
| 69 | $this->view->assign('type', 'other'); |
||
| 70 | $this->view->assign('toc', $this->makeMenuArray()); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * This builds a menu array for HMENU |
||
| 77 | * |
||
| 78 | * @access protected |
||
| 79 | * @return array HMENU array |
||
| 80 | */ |
||
| 81 | protected function makeMenuArray() |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * This builds a menu for list of 3D objects |
||
| 150 | * |
||
| 151 | * @access protected |
||
| 152 | * |
||
| 153 | * @param string $content: The PlugIn content |
||
| 154 | * @param array $conf: The PlugIn configuration |
||
| 155 | * |
||
| 156 | * @return array HMENU array |
||
| 157 | */ |
||
| 158 | protected function makeMenuFor3DObjects() |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * This builds an array for one menu entry |
||
| 171 | * |
||
| 172 | * @access protected |
||
| 173 | * |
||
| 174 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 175 | * @param bool $recursive : Whether to include the child entries |
||
| 176 | * |
||
| 177 | * @return array HMENU array for menu entry |
||
| 178 | */ |
||
| 179 | protected function getMenuEntry(array $entry, $recursive = false) |
||
| 180 | { |
||
| 181 | $entry = $this->resolveMenuEntry($entry); |
||
| 182 | |||
| 183 | $entryArray = []; |
||
| 184 | // Set "title", "volume", "type" and "pagination" from $entry array. |
||
| 185 | $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
||
| 186 | $entryArray['volume'] = $entry['volume']; |
||
| 187 | $entryArray['orderlabel'] = $entry['orderlabel']; |
||
| 188 | $entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['storagePid']); |
||
| 189 | $entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
||
| 190 | $entryArray['_OVERRIDE_HREF'] = ''; |
||
| 191 | $entryArray['doNotLinkIt'] = 1; |
||
| 192 | $entryArray['ITEM_STATE'] = 'NO'; |
||
| 193 | // Build menu links based on the $entry['points'] array. |
||
| 194 | if ( |
||
| 195 | !empty($entry['points']) |
||
| 196 | && MathUtility::canBeInterpretedAsInteger($entry['points']) |
||
| 197 | ) { |
||
| 198 | $entryArray['page'] = $entry['points']; |
||
| 199 | |||
| 200 | $entryArray['doNotLinkIt'] = 0; |
||
| 201 | if ($this->settings['basketButton']) { |
||
| 202 | $entryArray['basketButton'] = [ |
||
| 203 | 'logId' => $entry['id'], |
||
| 204 | 'startpage' => $entry['points'] |
||
| 205 | ]; |
||
| 206 | } |
||
| 207 | } elseif ( |
||
| 208 | !empty($entry['points']) |
||
| 209 | && is_string($entry['points']) |
||
| 210 | ) { |
||
| 211 | $entryArray['id'] = $entry['points']; |
||
| 212 | $entryArray['page'] = 1; |
||
| 213 | $entryArray['doNotLinkIt'] = 0; |
||
| 214 | if ($this->settings['basketButton']) { |
||
| 215 | $entryArray['basketButton'] = [ |
||
| 216 | 'logId' => $entry['id'], |
||
| 217 | 'startpage' => $entry['points'] |
||
| 218 | ]; |
||
| 219 | } |
||
| 220 | } elseif (!empty($entry['targetUid'])) { |
||
| 221 | $entryArray['id'] = $entry['targetUid']; |
||
| 222 | $entryArray['page'] = 1; |
||
| 223 | $entryArray['doNotLinkIt'] = 0; |
||
| 224 | if ($this->settings['basketButton']) { |
||
| 225 | $entryArray['basketButton'] = [ |
||
| 226 | 'logId' => $entry['id'], |
||
| 227 | 'startpage' => $entry['targetUid'] |
||
| 228 | ]; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | // Set "ITEM_STATE" to "CUR" if this entry points to current page. |
||
| 232 | if (in_array($entry['id'], $this->activeEntries)) { |
||
| 233 | $entryArray['ITEM_STATE'] = 'CUR'; |
||
| 234 | } |
||
| 235 | // Build sub-menu if available and called recursively. |
||
| 236 | if ( |
||
| 237 | $recursive === true |
||
| 238 | && !empty($entry['children']) |
||
| 239 | ) { |
||
| 240 | // Build sub-menu only if one of the following conditions apply: |
||
| 241 | // 1. Current menu node is in rootline |
||
| 242 | // 2. Current menu node points to another file |
||
| 243 | // 3. Current menu node has no corresponding images |
||
| 244 | if ( |
||
| 245 | $entryArray['ITEM_STATE'] == 'CUR' |
||
| 246 | || is_string($entry['points']) |
||
| 247 | || empty($this->document->getDoc()->smLinks['l2p'][$entry['id']]) |
||
| 248 | ) { |
||
| 249 | $entryArray['_SUB_MENU'] = []; |
||
| 250 | foreach ($entry['children'] as $child) { |
||
| 251 | // Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
||
| 252 | if (in_array($child['id'], $this->activeEntries)) { |
||
| 253 | $entryArray['ITEM_STATE'] = 'ACT'; |
||
| 254 | } |
||
| 255 | $entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true); |
||
| 256 | } |
||
| 257 | } |
||
| 258 | // Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
||
| 259 | $entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB'); |
||
| 260 | } |
||
| 261 | return $entryArray; |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * If $entry references an external METS file (as mptr), |
||
| 266 | * try to resolve its database UID and return an updated $entry. |
||
| 267 | * |
||
| 268 | * This is so that when linking from a child document back to its parent, |
||
| 269 | * that link is via UID, so that subsequently the parent's TOC is built from database. |
||
| 270 | * |
||
| 271 | * @param array $entry |
||
| 272 | * @return array |
||
| 273 | */ |
||
| 274 | protected function resolveMenuEntry($entry) |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * This builds an array for one 3D menu entry |
||
| 293 | * |
||
| 294 | * @access protected |
||
| 295 | * |
||
| 296 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 297 | * @param bool $recursive : Whether to include the child entries |
||
| 298 | * |
||
| 299 | * @return array HMENU array for 3D menu entry |
||
| 300 | */ |
||
| 301 | protected function getMenuEntryWithImage(array $entry, $recursive = false) |
||
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Check or possible combinations of requested params. |
||
| 357 | * |
||
| 358 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 359 | * |
||
| 360 | * @return bool true if found, false otherwise |
||
| 361 | */ |
||
| 362 | private function isFound($entry) { |
||
| 363 | if (!empty($this->requestData['title'] && !empty($this->requestData['types']) && !empty($this->requestData['author']))) { |
||
| 364 | return $this->isTitleFound($entry) && $this->isTypeFound($entry) && $this->isAuthorFound($entry); |
||
| 365 | } else if (!empty($this->requestData['title']) && !empty($this->requestData['author'])) { |
||
| 366 | return $this->isTitleFound($entry) && $this->isAuthorFound($entry); |
||
| 367 | } else if (!empty($this->requestData['title']) && !empty($this->requestData['types'])) { |
||
| 368 | return $this->isTitleFound($entry) && $this->isTypeFound($entry); |
||
| 369 | } else if (!empty($this->requestData['author']) && !empty($this->requestData['types'])) { |
||
| 370 | return $this->isAuthorFound($entry) && $this->isTypeFound($entry); |
||
| 371 | } else if (!empty($this->requestData['title'])) { |
||
| 372 | return $this->isTitleFound($entry); |
||
| 373 | } else if (!empty($this->requestData['types'])) { |
||
| 374 | return $this->isTypeFound($entry); |
||
| 375 | } else if (!empty($this->requestData['author'])) { |
||
| 376 | return $this->isAuthorFound($entry); |
||
| 377 | } else { |
||
| 378 | // no parameters so entry is matching |
||
| 379 | return true; |
||
| 380 | } |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Check if author is found. |
||
| 385 | * |
||
| 386 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 387 | * |
||
| 388 | * @return bool true if found, false otherwise |
||
| 389 | */ |
||
| 390 | private function isAuthorFound($entry) { |
||
| 391 | $value = strtolower($entry['author']); |
||
| 392 | $author = strtolower($this->requestData['author']); |
||
| 393 | return str_contains($value, $author); |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Check if title is found. |
||
| 398 | * |
||
| 399 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 400 | * |
||
| 401 | * @return bool true if found, false otherwise |
||
| 402 | */ |
||
| 403 | private function isTitleFound($entry) { |
||
| 404 | $value = strtolower($entry['label']); |
||
| 405 | $title = strtolower($this->requestData['title']); |
||
| 406 | return str_contains($value, $title); |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Check if type is found. |
||
| 411 | * |
||
| 412 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 413 | * |
||
| 414 | * @return bool true if found, false otherwise |
||
| 415 | */ |
||
| 416 | private function isTypeFound($entry) { |
||
| 417 | return str_contains($entry['identifier'], $this->requestData['types']); |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Get all types. |
||
| 422 | * |
||
| 423 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 424 | * |
||
| 425 | * @return array of object types |
||
| 426 | */ |
||
| 427 | private function getTypes($entry) { |
||
| 428 | $types = []; |
||
| 429 | $index = 0; |
||
| 430 | |||
| 431 | if (!empty($entry[0]['children'])) { |
||
| 432 | foreach ($entry[0]['children'] as $child) { |
||
| 433 | $type = $this->getType($child); |
||
| 434 | if (!(in_array($type, $types)) && $type != NULL) { |
||
| 435 | $types[$index] = $type; |
||
| 436 | $index++; |
||
| 437 | } |
||
| 438 | } |
||
| 439 | } |
||
| 440 | |||
| 441 | return $types; |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Get single type for given entry. |
||
| 446 | * |
||
| 447 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 448 | * |
||
| 449 | * @return string type name without number |
||
| 450 | */ |
||
| 451 | private function getType($entry) { |
||
| 457 | } |
||
| 458 | } |
||
| 459 |
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.