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