We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 40 |
| Total Lines | 264 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| 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 |
||
| 29 | class TableOfContentsController extends AbstractController |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * This holds the active entries according to the currently selected page |
||
| 33 | * |
||
| 34 | * @var array |
||
| 35 | * @access protected |
||
| 36 | */ |
||
| 37 | protected $activeEntries = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var ExtensionConfiguration |
||
| 41 | */ |
||
| 42 | protected $extensionConfiguration; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | protected $pluginConf; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * SearchController constructor. |
||
| 51 | */ |
||
| 52 | public function __construct() |
||
| 53 | { |
||
| 54 | $this->extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 55 | |||
| 56 | // Read plugin TS configuration. |
||
| 57 | $this->pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_tableofcontents.']; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * This builds an array for one menu entry |
||
| 62 | * |
||
| 63 | * @access protected |
||
| 64 | * |
||
| 65 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Document->getLogicalStructure |
||
| 66 | * @param bool $recursive : Whether to include the child entries |
||
| 67 | * |
||
| 68 | * @return array HMENU array for menu entry |
||
| 69 | */ |
||
| 70 | protected function getMenuEntry(array $entry, $recursive = false) |
||
| 71 | { |
||
| 72 | $entryArray = []; |
||
| 73 | // Set "title", "volume", "type" and "pagination" from $entry array. |
||
| 74 | $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
||
| 75 | $entryArray['volume'] = $entry['volume']; |
||
| 76 | $entryArray['orderlabel'] = $entry['orderlabel']; |
||
| 77 | $entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['pages']); |
||
| 78 | $entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
||
| 79 | $entryArray['_OVERRIDE_HREF'] = ''; |
||
| 80 | $entryArray['doNotLinkIt'] = 1; |
||
| 81 | $entryArray['ITEM_STATE'] = 'NO'; |
||
| 82 | // Build menu links based on the $entry['points'] array. |
||
| 83 | if ( |
||
| 84 | !empty($entry['points']) |
||
| 85 | && MathUtility::canBeInterpretedAsInteger($entry['points']) |
||
| 86 | ) { |
||
| 87 | $entryArray['page'] = $entry['points']; |
||
| 88 | |||
| 89 | $entryArray['doNotLinkIt'] = 0; |
||
| 90 | if ($this->settings['basketButton']) { |
||
| 91 | $entryArray['basketButton'] = [ |
||
| 92 | 'logId' => $entry['id'], |
||
| 93 | 'startpage' => $entry['points'] |
||
| 94 | ]; |
||
| 95 | } |
||
| 96 | } elseif ( |
||
| 97 | !empty($entry['points']) |
||
| 98 | && is_string($entry['points']) |
||
| 99 | ) { |
||
| 100 | $entryArray['id'] = $entry['points']; |
||
| 101 | $entryArray['page'] = 1; |
||
| 102 | $entryArray['doNotLinkIt'] = 0; |
||
| 103 | if ($this->settings['basketButton']) { |
||
| 104 | $entryArray['basketButton'] = [ |
||
| 105 | 'logId' => $entry['id'], |
||
| 106 | 'startpage' => $entry['points'] |
||
| 107 | ]; |
||
| 108 | } |
||
| 109 | } elseif (!empty($entry['targetUid'])) { |
||
| 110 | $entryArray['id'] = $entry['targetUid']; |
||
| 111 | $entryArray['page'] = 1; |
||
| 112 | $entryArray['doNotLinkIt'] = 0; |
||
| 113 | if ($this->settings['basketButton']) { |
||
| 114 | $entryArray['basketButton'] = [ |
||
| 115 | 'logId' => $entry['id'], |
||
| 116 | 'startpage' => $entry['targetUid'] |
||
| 117 | ]; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | // Set "ITEM_STATE" to "CUR" if this entry points to current page. |
||
| 121 | if (in_array($entry['id'], $this->activeEntries)) { |
||
| 122 | $entryArray['ITEM_STATE'] = 'CUR'; |
||
| 123 | } |
||
| 124 | // Build sub-menu if available and called recursively. |
||
| 125 | if ( |
||
| 126 | $recursive === true |
||
| 127 | && !empty($entry['children']) |
||
| 128 | ) { |
||
| 129 | // Build sub-menu only if one of the following conditions apply: |
||
| 130 | // 1. "expAll" is set for menu |
||
| 131 | // 2. Current menu node is in rootline |
||
| 132 | // 3. Current menu node points to another file |
||
| 133 | // 4. Current menu node has no corresponding images |
||
| 134 | if ( |
||
| 135 | !empty($this->pluginConf['menuConf.']['expAll']) |
||
| 136 | || $entryArray['ITEM_STATE'] == 'CUR' |
||
| 137 | || is_string($entry['points']) |
||
| 138 | || empty($this->doc->smLinks['l2p'][$entry['id']]) |
||
| 139 | ) { |
||
| 140 | $entryArray['_SUB_MENU'] = []; |
||
| 141 | foreach ($entry['children'] as $child) { |
||
| 142 | // Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
||
| 143 | if (in_array($child['id'], $this->activeEntries)) { |
||
| 144 | $entryArray['ITEM_STATE'] = 'ACT'; |
||
| 145 | } |
||
| 146 | $entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | // Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
||
| 150 | $entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB'); |
||
| 151 | } |
||
| 152 | return $entryArray; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * The main method of the plugin |
||
| 157 | * |
||
| 158 | * @return void |
||
| 159 | */ |
||
| 160 | public function mainAction() |
||
| 161 | { |
||
| 162 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 163 | unset($requestData['__referrer'], $requestData['__trustedProperties']); |
||
| 164 | |||
| 165 | // Check for typoscript configuration to prevent fatal error. |
||
| 166 | if (empty($this->pluginConf['menuConf.'])) { |
||
| 167 | $this->logger->warning('Incomplete plugin configuration'); |
||
|
1 ignored issue
–
show
|
|||
| 168 | } |
||
| 169 | |||
| 170 | $this->view->assign('toc', $this->makeMenuArray($requestData)); |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * This builds a menu array for HMENU |
||
| 175 | * |
||
| 176 | * @access public |
||
| 177 | * @param array $requestData |
||
| 178 | * @return array HMENU array |
||
| 179 | */ |
||
| 180 | public function makeMenuArray($requestData) |
||
| 293 | } |
||
| 294 | } |
||
| 295 |
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.