We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 83 |
| Total Lines | 416 |
| Duplicated Lines | 0 % |
| Changes | 9 | ||
| Bugs | 0 | 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 |
||
| 26 | class TableOfContentsController extends AbstractController |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * This holds the active entries according to the currently selected page |
||
| 30 | * |
||
| 31 | * @var array |
||
| 32 | * @access protected |
||
| 33 | */ |
||
| 34 | protected $activeEntries = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The main method of the plugin |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | public function mainAction() |
||
| 42 | { |
||
| 43 | // Load current document. |
||
| 44 | $this->loadDocument($this->requestData); |
||
| 45 | if ( |
||
| 46 | $this->document === null |
||
| 47 | || $this->document->getDoc() === null |
||
| 48 | ) { |
||
| 49 | // Quit without doing anything if required variables are not set. |
||
| 50 | return; |
||
| 51 | } else { |
||
| 52 | if (!empty($this->requestData['logicalPage'])) { |
||
| 53 | $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
||
| 54 | // The logical page parameter should not appear again |
||
| 55 | unset($this->requestData['logicalPage']); |
||
| 56 | } |
||
| 57 | if ($this->document->getDoc()->tableOfContents[0]['type'] == 'collection') { |
||
| 58 | $this->view->assign('currentList', $this->requestData['id']); |
||
| 59 | if (isset($this->requestData['transform'])) { |
||
| 60 | $this->view->assign('transform', $this->requestData['transform']); |
||
| 61 | } else { |
||
| 62 | $this->view->assign('transform', 'something'); |
||
| 63 | } |
||
| 64 | $this->view->assign('type', 'collection'); |
||
| 65 | $this->view->assign('types', $this->getTypes($this->document->getDoc()->tableOfContents)); |
||
| 66 | $this->view->assign('toc', $this->makeMenuFor3DObjects()); |
||
| 67 | } else { |
||
| 68 | $this->view->assign('type', 'other'); |
||
| 69 | $this->view->assign('toc', $this->makeMenuArray()); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * This builds a menu array for HMENU |
||
| 76 | * |
||
| 77 | * @access protected |
||
| 78 | * @return array HMENU array |
||
| 79 | */ |
||
| 80 | protected function makeMenuArray() |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * This builds a menu for list of 3D objects |
||
| 149 | * |
||
| 150 | * @access protected |
||
| 151 | * |
||
| 152 | * @param string $content: The PlugIn content |
||
| 153 | * @param array $conf: The PlugIn configuration |
||
| 154 | * |
||
| 155 | * @return array HMENU array |
||
| 156 | */ |
||
| 157 | protected function makeMenuFor3DObjects() |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * This builds an array for one menu entry |
||
| 183 | * |
||
| 184 | * @access protected |
||
| 185 | * |
||
| 186 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 187 | * @param bool $recursive : Whether to include the child entries |
||
| 188 | * |
||
| 189 | * @return array HMENU array for menu entry |
||
| 190 | */ |
||
| 191 | protected function getMenuEntry(array $entry, $recursive = false) |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * This builds an array for one 3D menu entry |
||
| 276 | * |
||
| 277 | * @access protected |
||
| 278 | * |
||
| 279 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 280 | * @param bool $recursive : Whether to include the child entries |
||
| 281 | * |
||
| 282 | * @return array HMENU array for 3D menu entry |
||
| 283 | */ |
||
| 284 | protected function getMenuEntryWithImage(array $entry, $recursive = false) |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Check or possible combinations of requested params. |
||
| 342 | * |
||
| 343 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 344 | * |
||
| 345 | * @return bool true if found, false otherwise |
||
| 346 | */ |
||
| 347 | private function isFound($entry) { |
||
| 348 | if (!empty($this->requestData['title'] && !empty($this->requestData['types']) && !empty($this->requestData['author']))) { |
||
| 349 | return $this->isTitleFound($entry) && $this->isTypeFound($entry) && $this->isAuthorFound($entry); |
||
| 350 | } else if (!empty($this->requestData['title']) && !empty($this->requestData['author'])) { |
||
| 351 | return $this->isTitleFound($entry) && $this->isAuthorFound($entry); |
||
| 352 | } else if (!empty($this->requestData['title']) && !empty($this->requestData['types'])) { |
||
| 353 | return $this->isTitleFound($entry) && $this->isTypeFound($entry); |
||
| 354 | } else if (!empty($this->requestData['author']) && !empty($this->requestData['types'])) { |
||
| 355 | return $this->isAuthorFound($entry) && $this->isTypeFound($entry); |
||
| 356 | } else if (!empty($this->requestData['title'])) { |
||
| 357 | return $this->isTitleFound($entry); |
||
| 358 | } else if (!empty($this->requestData['types'])) { |
||
| 359 | return $this->isTypeFound($entry); |
||
| 360 | } else if (!empty($this->requestData['author'])) { |
||
| 361 | return $this->isAuthorFound($entry); |
||
| 362 | } else { |
||
| 363 | // no parameters so entry is matching |
||
| 364 | return true; |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Check if author is found. |
||
| 370 | * |
||
| 371 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 372 | * |
||
| 373 | * @return bool true if found, false otherwise |
||
| 374 | */ |
||
| 375 | private function isAuthorFound($entry) { |
||
| 376 | $value = strtolower($entry['author']); |
||
| 377 | $author = strtolower($this->requestData['author']); |
||
| 378 | return str_contains($value, $author); |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Check if title is found. |
||
| 383 | * |
||
| 384 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 385 | * |
||
| 386 | * @return bool true if found, false otherwise |
||
| 387 | */ |
||
| 388 | private function isTitleFound($entry) { |
||
| 389 | $value = strtolower($entry['label']); |
||
| 390 | $title = strtolower($this->requestData['title']); |
||
| 391 | return str_contains($value, $title); |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Check if type is found. |
||
| 396 | * |
||
| 397 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 398 | * |
||
| 399 | * @return bool true if found, false otherwise |
||
| 400 | */ |
||
| 401 | private function isTypeFound($entry) { |
||
| 402 | return str_contains($entry['identifier'], $this->requestData['types']); |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Get all types. |
||
| 407 | * |
||
| 408 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 409 | * |
||
| 410 | * @return array of object types |
||
| 411 | */ |
||
| 412 | private function getTypes($entry) { |
||
| 413 | $types = []; |
||
| 414 | $index = 0; |
||
| 415 | |||
| 416 | if (!empty($entry[0]['children'])) { |
||
| 417 | foreach ($entry[0]['children'] as $child) { |
||
| 418 | $type = $this->getType($child); |
||
| 419 | if (!(in_array($type, $types)) && $type != NULL) { |
||
| 420 | $types[$index] = $type; |
||
| 421 | $index++; |
||
| 422 | } |
||
| 423 | } |
||
| 424 | } |
||
| 425 | |||
| 426 | return $types; |
||
| 427 | } |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Get single type for given entry. |
||
| 431 | * |
||
| 432 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
||
| 433 | * |
||
| 434 | * @return string type name without number |
||
| 435 | */ |
||
| 436 | private function getType($entry) { |
||
| 442 | } |
||
| 443 | } |
||
| 444 |
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.