We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 47 |
| Total Lines | 334 |
| 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 |
||
| 31 | class TableOfContentsController extends ActionController |
||
| 32 | { |
||
| 33 | protected $prefixId = 'tx_dlf'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * This holds the active entries according to the currently selected page |
||
| 37 | * |
||
| 38 | * @var array |
||
| 39 | * @access protected |
||
| 40 | */ |
||
| 41 | protected $activeEntries = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var ExtensionConfiguration |
||
| 45 | */ |
||
| 46 | protected $extensionConfiguration; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var ConfigurationManager |
||
| 50 | */ |
||
| 51 | protected $configurationManager; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var \TYPO3\CMS\Core\Log\LogManager |
||
| 55 | */ |
||
| 56 | protected $logger; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected $pluginConf; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * SearchController constructor. |
||
| 65 | */ |
||
| 66 | public function __construct() |
||
| 67 | { |
||
| 68 | $this->configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
||
| 69 | $this->logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__); |
||
| 70 | $this->extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 71 | |||
| 72 | // Read plugin TS configuration. |
||
| 73 | $this->pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_tableofcontents.']; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * This builds an array for one menu entry |
||
| 78 | * |
||
| 79 | * @access protected |
||
| 80 | * |
||
| 81 | * @param array $entry : The entry's array from \Kitodo\Dlf\Common\Document->getLogicalStructure |
||
| 82 | * @param bool $recursive : Whether to include the child entries |
||
| 83 | * |
||
| 84 | * @return array HMENU array for menu entry |
||
| 85 | */ |
||
| 86 | protected function getMenuEntry(array $entry, $recursive = false) |
||
| 87 | { |
||
| 88 | $entryArray = []; |
||
| 89 | // Set "title", "volume", "type" and "pagination" from $entry array. |
||
| 90 | $entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
||
| 91 | $entryArray['volume'] = $entry['volume']; |
||
| 92 | $entryArray['orderlabel'] = $entry['orderlabel']; |
||
| 93 | $entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['pages']); |
||
| 94 | $entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
||
| 95 | $entryArray['_OVERRIDE_HREF'] = ''; |
||
| 96 | $entryArray['doNotLinkIt'] = 1; |
||
| 97 | $entryArray['ITEM_STATE'] = 'NO'; |
||
| 98 | // Build menu links based on the $entry['points'] array. |
||
| 99 | if ( |
||
| 100 | !empty($entry['points']) |
||
| 101 | && MathUtility::canBeInterpretedAsInteger($entry['points']) |
||
| 102 | ) { |
||
| 103 | $entryArray['page'] = $entry['points']; |
||
| 104 | |||
| 105 | $entryArray['doNotLinkIt'] = 0; |
||
| 106 | if ($this->settings['basketButton']) { |
||
| 107 | $entryArray['basketButton'] = [ |
||
| 108 | 'logId' => $entry['id'], |
||
| 109 | 'startpage' => $entry['points'] |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | } elseif ( |
||
| 113 | !empty($entry['points']) |
||
| 114 | && is_string($entry['points']) |
||
| 115 | ) { |
||
| 116 | $entryArray['id'] = $entry['points']; |
||
| 117 | $entryArray['page'] = 1; |
||
| 118 | $entryArray['doNotLinkIt'] = 0; |
||
| 119 | if ($this->settings['basketButton']) { |
||
| 120 | $entryArray['basketButton'] = [ |
||
| 121 | 'logId' => $entry['id'], |
||
| 122 | 'startpage' => $entry['points'] |
||
| 123 | ]; |
||
| 124 | } |
||
| 125 | } elseif (!empty($entry['targetUid'])) { |
||
| 126 | $entryArray['id'] = $entry['targetUid']; |
||
| 127 | $entryArray['page'] = 1; |
||
| 128 | $entryArray['doNotLinkIt'] = 0; |
||
| 129 | if ($this->settings['basketButton']) { |
||
| 130 | $entryArray['basketButton'] = [ |
||
| 131 | 'logId' => $entry['id'], |
||
| 132 | 'startpage' => $entry['targetUid'] |
||
| 133 | ]; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | // Set "ITEM_STATE" to "CUR" if this entry points to current page. |
||
| 137 | if (in_array($entry['id'], $this->activeEntries)) { |
||
| 138 | $entryArray['ITEM_STATE'] = 'CUR'; |
||
| 139 | } |
||
| 140 | // Build sub-menu if available and called recursively. |
||
| 141 | if ( |
||
| 142 | $recursive == true |
||
| 143 | && !empty($entry['children']) |
||
| 144 | ) { |
||
| 145 | // Build sub-menu only if one of the following conditions apply: |
||
| 146 | // 1. "expAll" is set for menu |
||
| 147 | // 2. Current menu node is in rootline |
||
| 148 | // 3. Current menu node points to another file |
||
| 149 | // 4. Current menu node has no corresponding images |
||
| 150 | if ( |
||
| 151 | !empty($this->pluginConf['menuConf.']['expAll']) |
||
| 152 | || $entryArray['ITEM_STATE'] == 'CUR' |
||
| 153 | || is_string($entry['points']) |
||
| 154 | || empty($this->doc->smLinks['l2p'][$entry['id']]) |
||
| 155 | ) { |
||
| 156 | $entryArray['_SUB_MENU'] = []; |
||
| 157 | foreach ($entry['children'] as $child) { |
||
| 158 | // Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
||
| 159 | if (in_array($child['id'], $this->activeEntries)) { |
||
| 160 | $entryArray['ITEM_STATE'] = 'ACT'; |
||
| 161 | } |
||
| 162 | $entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | // Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
||
| 166 | $entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB'); |
||
| 167 | } |
||
| 168 | return $entryArray; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * The main method of the PlugIn |
||
| 173 | * |
||
| 174 | * @access public |
||
| 175 | */ |
||
| 176 | public function mainAction() |
||
| 177 | { |
||
| 178 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 179 | unset($requestData['__referrer'], $requestData['__trustedProperties']); |
||
| 180 | |||
| 181 | // Check for typoscript configuration to prevent fatal error. |
||
| 182 | if (empty($this->pluginConf['menuConf.'])) { |
||
| 183 | $this->logger->warning('Incomplete plugin configuration'); |
||
|
1 ignored issue
–
show
|
|||
| 184 | } |
||
| 185 | |||
| 186 | $this->view->assign('toc', $this->makeMenuArray($requestData)); |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * This builds a menu array for HMENU |
||
| 191 | * |
||
| 192 | * @access public |
||
| 193 | * @param array $requestData |
||
| 194 | * @return array HMENU array |
||
| 195 | */ |
||
| 196 | public function makeMenuArray($requestData) |
||
| 309 | } |
||
| 310 | |||
| 311 | // TODO: Needs to be placed in an abstract class |
||
| 312 | /** |
||
| 313 | * Loads the current document into $this->doc |
||
| 314 | * |
||
| 315 | * @access protected |
||
| 316 | * |
||
| 317 | * @return void |
||
| 318 | */ |
||
| 319 | protected function loadDocument($requestData) |
||
| 365 | } |
||
| 366 | } |
||
| 367 | } |
||
| 368 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths