We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 41 | 
| Total Lines | 229 | 
| 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 | |||
| 59 |             $this->view->assign('toc', $this->makeMenuArray()); | 
            ||
| 60 | }  | 
            ||
| 61 | }  | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * This builds a menu array for HMENU  | 
            ||
| 65 | *  | 
            ||
| 66 | * @access protected  | 
            ||
| 67 | * @return array HMENU array  | 
            ||
| 68 | */  | 
            ||
| 69 | protected function makeMenuArray()  | 
            ||
| 134 | }  | 
            ||
| 135 | |||
| 136 | /**  | 
            ||
| 137 | * This builds an array for one menu entry  | 
            ||
| 138 | *  | 
            ||
| 139 | * @access protected  | 
            ||
| 140 | *  | 
            ||
| 141 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure  | 
            ||
| 142 | * @param bool $recursive : Whether to include the child entries  | 
            ||
| 143 | *  | 
            ||
| 144 | * @return array HMENU array for menu entry  | 
            ||
| 145 | */  | 
            ||
| 146 | protected function getMenuEntry(array $entry, $recursive = false)  | 
            ||
| 147 |     { | 
            ||
| 148 | $entry = $this->resolveMenuEntry($entry);  | 
            ||
| 149 | |||
| 150 | $entryArray = [];  | 
            ||
| 151 | // Set "title", "volume", "type" and "pagination" from $entry array.  | 
            ||
| 152 | $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel'];  | 
            ||
| 153 | $entryArray['volume'] = $entry['volume'];  | 
            ||
| 154 | $entryArray['orderlabel'] = $entry['orderlabel'];  | 
            ||
| 155 | $entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['storagePid']);  | 
            ||
| 156 | $entryArray['pagination'] = htmlspecialchars($entry['pagination']);  | 
            ||
| 157 | $entryArray['_OVERRIDE_HREF'] = '';  | 
            ||
| 158 | $entryArray['doNotLinkIt'] = 1;  | 
            ||
| 159 | $entryArray['ITEM_STATE'] = 'NO';  | 
            ||
| 160 | // Build menu links based on the $entry['points'] array.  | 
            ||
| 161 | if (  | 
            ||
| 162 | !empty($entry['points'])  | 
            ||
| 163 | && MathUtility::canBeInterpretedAsInteger($entry['points'])  | 
            ||
| 164 |         ) { | 
            ||
| 165 | $entryArray['page'] = $entry['points'];  | 
            ||
| 166 | |||
| 167 | $entryArray['doNotLinkIt'] = 0;  | 
            ||
| 168 |             if ($this->settings['basketButton']) { | 
            ||
| 169 | $entryArray['basketButton'] = [  | 
            ||
| 170 | 'logId' => $entry['id'],  | 
            ||
| 171 | 'startpage' => $entry['points']  | 
            ||
| 172 | ];  | 
            ||
| 173 | }  | 
            ||
| 174 | } elseif (  | 
            ||
| 175 | !empty($entry['points'])  | 
            ||
| 176 | && is_string($entry['points'])  | 
            ||
| 177 |         ) { | 
            ||
| 178 | $entryArray['id'] = $entry['points'];  | 
            ||
| 179 | $entryArray['page'] = 1;  | 
            ||
| 180 | $entryArray['doNotLinkIt'] = 0;  | 
            ||
| 181 |             if ($this->settings['basketButton']) { | 
            ||
| 182 | $entryArray['basketButton'] = [  | 
            ||
| 183 | 'logId' => $entry['id'],  | 
            ||
| 184 | 'startpage' => $entry['points']  | 
            ||
| 185 | ];  | 
            ||
| 186 | }  | 
            ||
| 187 |         } elseif (!empty($entry['targetUid'])) { | 
            ||
| 188 | $entryArray['id'] = $entry['targetUid'];  | 
            ||
| 189 | $entryArray['page'] = 1;  | 
            ||
| 190 | $entryArray['doNotLinkIt'] = 0;  | 
            ||
| 191 |             if ($this->settings['basketButton']) { | 
            ||
| 192 | $entryArray['basketButton'] = [  | 
            ||
| 193 | 'logId' => $entry['id'],  | 
            ||
| 194 | 'startpage' => $entry['targetUid']  | 
            ||
| 195 | ];  | 
            ||
| 196 | }  | 
            ||
| 197 | }  | 
            ||
| 198 | // Set "ITEM_STATE" to "CUR" if this entry points to current page.  | 
            ||
| 199 |         if (in_array($entry['id'], $this->activeEntries)) { | 
            ||
| 200 | $entryArray['ITEM_STATE'] = 'CUR';  | 
            ||
| 201 | }  | 
            ||
| 202 | // Build sub-menu if available and called recursively.  | 
            ||
| 203 | if (  | 
            ||
| 204 | $recursive === true  | 
            ||
| 205 | && !empty($entry['children'])  | 
            ||
| 206 |         ) { | 
            ||
| 207 | // Build sub-menu only if one of the following conditions apply:  | 
            ||
| 208 | // 1. Current menu node is in rootline  | 
            ||
| 209 | // 2. Current menu node points to another file  | 
            ||
| 210 | // 3. Current menu node has no corresponding images  | 
            ||
| 211 | if (  | 
            ||
| 212 | $entryArray['ITEM_STATE'] == 'CUR'  | 
            ||
| 213 | || is_string($entry['points'])  | 
            ||
| 214 | || empty($this->document->getDoc()->smLinks['l2p'][$entry['id']])  | 
            ||
| 215 |             ) { | 
            ||
| 216 | $entryArray['_SUB_MENU'] = [];  | 
            ||
| 217 |                 foreach ($entry['children'] as $child) { | 
            ||
| 218 | // Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page.  | 
            ||
| 219 |                     if (in_array($child['id'], $this->activeEntries)) { | 
            ||
| 220 | $entryArray['ITEM_STATE'] = 'ACT';  | 
            ||
| 221 | }  | 
            ||
| 222 | $entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true);  | 
            ||
| 223 | }  | 
            ||
| 224 | }  | 
            ||
| 225 | // Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries.  | 
            ||
| 226 | $entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB');  | 
            ||
| 227 | }  | 
            ||
| 228 | return $entryArray;  | 
            ||
| 229 | }  | 
            ||
| 230 | |||
| 231 | /**  | 
            ||
| 232 | * If $entry references an external METS file (as mptr),  | 
            ||
| 233 | * try to resolve its database UID and return an updated $entry.  | 
            ||
| 234 | *  | 
            ||
| 235 | * This is so that when linking from a child document back to its parent,  | 
            ||
| 236 | * that link is via UID, so that subsequently the parent's TOC is built from database.  | 
            ||
| 237 | *  | 
            ||
| 238 | * @param array $entry  | 
            ||
| 239 | * @return array  | 
            ||
| 240 | */  | 
            ||
| 241 | protected function resolveMenuEntry($entry)  | 
            ||
| 256 | }  | 
            ||
| 257 | }  | 
            ||
| 258 | 
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.