We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 88 |
| Total Lines | 497 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ToolboxController 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 ToolboxController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class ToolboxController extends AbstractController |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * The main method of the plugin |
||
| 23 | * |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public function mainAction() |
||
| 27 | { |
||
| 28 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 29 | unset($requestData['__referrer'], $requestData['__trustedProperties']); |
||
| 30 | |||
| 31 | $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 32 | |||
| 33 | // Quit without doing anything if required variable is not set. |
||
| 34 | if (empty($requestData['id'])) { |
||
| 35 | return; |
||
| 36 | } |
||
| 37 | |||
| 38 | $requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0); |
||
| 39 | $this->view->assign('double', $requestData['double']); |
||
| 40 | |||
| 41 | // Load current document. |
||
| 42 | $this->loadDocument($requestData); |
||
| 43 | |||
| 44 | $tools = explode(',', $this->settings['tools']); |
||
| 45 | // Add the tools to the toolbox. |
||
| 46 | foreach ($tools as $tool) { |
||
| 47 | $tool = trim(str_replace('tx_dlf_', '', $tool)); |
||
| 48 | $this->$tool($requestData); |
||
| 49 | $this->view->assign($tool, true); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Renders the annotation tool |
||
| 55 | * @param $requestData |
||
| 56 | * @return void |
||
| 57 | */ |
||
| 58 | public function annotationtool($requestData) |
||
| 59 | { |
||
| 60 | if ( |
||
| 61 | $this->doc === null |
||
| 62 | || $this->doc->numPages < 1 |
||
| 63 | ) { |
||
| 64 | // Quit without doing anything if required variables are not set. |
||
| 65 | return; |
||
| 66 | } else { |
||
| 67 | if (!empty($requestData['logicalPage'])) { |
||
| 68 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 69 | // The logical page parameter should not appear again |
||
| 70 | unset($requestData['logicalPage']); |
||
| 71 | } |
||
| 72 | // Set default values if not set. |
||
| 73 | // $requestData['page'] may be integer or string (physical structure @ID) |
||
| 74 | if ( |
||
| 75 | (int) $requestData['page'] > 0 |
||
| 76 | || empty($requestData['page']) |
||
| 77 | ) { |
||
| 78 | $requestData['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
||
| 79 | } else { |
||
| 80 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $annotationContainers = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['annotationContainers']; |
||
| 85 | if ( |
||
| 86 | $annotationContainers != null |
||
| 87 | && sizeof($annotationContainers) > 0 |
||
| 88 | ) { |
||
| 89 | $this->view->assign('annotationTool', true); |
||
| 90 | } else { |
||
| 91 | $this->view->assign('annotationTool', false); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Renders the fulltext download tool |
||
| 97 | * @param $requestData |
||
| 98 | * @return void |
||
| 99 | */ |
||
| 100 | public function fulltextdownloadtool($requestData) |
||
| 101 | { |
||
| 102 | if ( |
||
| 103 | $this->doc === null |
||
| 104 | || $this->doc->numPages < 1 |
||
| 105 | || empty($this->extConf['fileGrpFulltext']) |
||
| 106 | ) { |
||
| 107 | // Quit without doing anything if required variables are not set. |
||
| 108 | return; |
||
| 109 | } else { |
||
| 110 | if (!empty($requestData['logicalPage'])) { |
||
| 111 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 112 | // The logical page parameter should not appear again |
||
| 113 | unset($requestData['logicalPage']); |
||
| 114 | } |
||
| 115 | // Set default values if not set. |
||
| 116 | // $requestData['page'] may be integer or string (physical structure @ID) |
||
| 117 | if ( |
||
| 118 | (int) $requestData['page'] > 0 |
||
| 119 | || empty($requestData['page']) |
||
| 120 | ) { |
||
| 121 | $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
||
| 122 | } else { |
||
| 123 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | // Get text download. |
||
| 127 | $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']); |
||
| 128 | while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
||
| 129 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext])) { |
||
| 130 | $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext]; |
||
| 131 | break; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | if (!empty($fullTextFile)) { |
||
| 135 | $this->view->assign('fulltextDownload', true); |
||
| 136 | } else { |
||
| 137 | $this->view->assign('fulltextDownload', false); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Renders the fulltext tool |
||
| 143 | * @param $requestData |
||
| 144 | * @return void |
||
| 145 | */ |
||
| 146 | public function fulltexttool($requestData) |
||
| 147 | { |
||
| 148 | if ( |
||
| 149 | $this->doc === null |
||
| 150 | || $this->doc->numPages < 1 |
||
| 151 | || empty($this->extConf['fileGrpFulltext']) |
||
| 152 | ) { |
||
| 153 | // Quit without doing anything if required variables are not set. |
||
| 154 | return; |
||
| 155 | } else { |
||
| 156 | if (!empty($requestData['logicalPage'])) { |
||
| 157 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 158 | // The logical page parameter should not appear again |
||
| 159 | unset($requestData['logicalPage']); |
||
| 160 | } |
||
| 161 | // Set default values if not set. |
||
| 162 | // $requestData['page'] may be integer or string (physical structure @ID) |
||
| 163 | if ( |
||
| 164 | (int) $requestData['page'] > 0 |
||
| 165 | || empty($requestData['page']) |
||
| 166 | ) { |
||
| 167 | $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
||
| 168 | } else { |
||
| 169 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 170 | } |
||
| 171 | } |
||
| 172 | $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']); |
||
| 173 | while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
||
| 174 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext])) { |
||
| 175 | $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext]; |
||
| 176 | break; |
||
| 177 | } |
||
| 178 | } |
||
| 179 | if (!empty($fullTextFile)) { |
||
| 180 | $this->view->assign('fulltext', true); |
||
| 181 | $this->view->assign('activateFullTextInitially', MathUtility::forceIntegerInRange($this->settings['activateFullTextInitially'], 0, 1, 0)); |
||
| 182 | } else { |
||
| 183 | $this->view->assign('fulltext', false); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Renders the image download tool |
||
| 189 | * @param $requestData |
||
| 190 | * @return void |
||
| 191 | */ |
||
| 192 | public function imagedownloadtool($requestData) |
||
| 193 | { |
||
| 194 | if ( |
||
| 195 | $this->doc === null |
||
| 196 | || $this->doc->numPages < 1 |
||
| 197 | || empty($this->settings['fileGrpsImageDownload']) |
||
| 198 | ) { |
||
| 199 | // Quit without doing anything if required variables are not set. |
||
| 200 | return; |
||
| 201 | } else { |
||
| 202 | if (!empty($requestData['logicalPage'])) { |
||
| 203 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 204 | // The logical page parameter should not appear again |
||
| 205 | unset($requestData['logicalPage']); |
||
| 206 | } |
||
| 207 | // Set default values if not set. |
||
| 208 | // $requestData['page'] may be integer or string (physical structure @ID) |
||
| 209 | if ( |
||
| 210 | (int) $requestData['page'] > 0 |
||
| 211 | || empty($requestData['page']) |
||
| 212 | ) { |
||
| 213 | $requestData['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
||
| 214 | } else { |
||
| 215 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | $imageArray = []; |
||
| 219 | // Get left or single page download. |
||
| 220 | $imageArray[0] = $this->getImage($requestData['page']); |
||
| 221 | if ($requestData['double'] == 1) { |
||
| 222 | $imageArray[1] = $this->getImage($requestData['page'] + 1); |
||
| 223 | } |
||
| 224 | $this->view->assign('imageDownload', $imageArray); |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Get image's URL and MIME type |
||
| 229 | * |
||
| 230 | * @access protected |
||
| 231 | * |
||
| 232 | * @param int $page: Page number |
||
| 233 | * |
||
| 234 | * @return array Array of image links and image format information |
||
| 235 | */ |
||
| 236 | protected function getImage($page) |
||
| 237 | { |
||
| 238 | $image = []; |
||
| 239 | // Get @USE value of METS fileGrp. |
||
| 240 | $fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload']); |
||
| 241 | while ($fileGrp = @array_pop($fileGrps)) { |
||
| 242 | // Get image link. |
||
| 243 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) { |
||
| 244 | $image['url'] = $this->doc->getDownloadLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]); |
||
| 245 | $image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]); |
||
| 246 | switch ($image['mimetype']) { |
||
| 247 | case 'image/jpeg': |
||
| 248 | $mimetypeLabel = ' (JPG)'; |
||
| 249 | break; |
||
| 250 | case 'image/tiff': |
||
| 251 | $mimetypeLabel = ' (TIFF)'; |
||
| 252 | break; |
||
| 253 | default: |
||
| 254 | $mimetypeLabel = ''; |
||
| 255 | } |
||
| 256 | $image['mimetypeLabel'] = $mimetypeLabel; |
||
| 257 | break; |
||
| 258 | } else { |
||
| 259 | $this->logger->warning('File not found in fileGrp "' . $fileGrp . '"'); |
||
|
1 ignored issue
–
show
|
|||
| 260 | } |
||
| 261 | } |
||
| 262 | return $image; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Renders the image manipulation tool |
||
| 267 | * @param $requestData |
||
| 268 | */ |
||
| 269 | public function imagemanipulationtool($requestData) |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Renders the PDF download tool |
||
| 280 | * @param $requestData |
||
| 281 | * @return void |
||
| 282 | */ |
||
| 283 | public function pdfdownloadtool($requestData) |
||
| 284 | { |
||
| 285 | if ( |
||
| 286 | $this->doc === null |
||
| 287 | || $this->doc->numPages < 1 |
||
| 288 | || empty($this->extConf['fileGrpDownload']) |
||
| 289 | ) { |
||
| 290 | // Quit without doing anything if required variables are not set. |
||
| 291 | return; |
||
| 292 | } else { |
||
| 293 | if (!empty($requestData['logicalPage'])) { |
||
| 294 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 295 | // The logical page parameter should not appear again |
||
| 296 | unset($requestData['logicalPage']); |
||
| 297 | } |
||
| 298 | // Set default values if not set. |
||
| 299 | // $requestData['page'] may be integer or string (physical structure @ID) |
||
| 300 | if ( |
||
| 301 | (int) $requestData['page'] > 0 |
||
| 302 | || empty($requestData['page']) |
||
| 303 | ) { |
||
| 304 | $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
||
| 305 | } else { |
||
| 306 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 307 | } |
||
| 308 | } |
||
| 309 | // Get single page downloads. |
||
| 310 | $this->view->assign('pageLinks', $this->getPageLink($requestData)); |
||
| 311 | // Get work download. |
||
| 312 | $this->view->assign('workLink', $this->getWorkLink()); |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Get page's download link |
||
| 317 | * |
||
| 318 | * @access protected |
||
| 319 | * |
||
| 320 | * @return array Link to downloadable page |
||
| 321 | */ |
||
| 322 | protected function getPageLink($requestData) |
||
| 323 | { |
||
| 324 | $page1Link = ''; |
||
| 325 | $page2Link = ''; |
||
| 326 | $pageLinkArray = []; |
||
| 327 | $pageNumber = $requestData['page']; |
||
| 328 | $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']); |
||
| 329 | // Get image link. |
||
| 330 | while ($fileGrpDownload = array_shift($fileGrpsDownload)) { |
||
| 331 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload])) { |
||
| 332 | $page1Link = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload]); |
||
| 333 | // Get second page, too, if double page view is activated. |
||
| 334 | if ( |
||
| 335 | $requestData['double'] |
||
| 336 | && $pageNumber < $this->doc->numPages |
||
| 337 | && !empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload]) |
||
| 338 | ) { |
||
| 339 | $page2Link = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload]); |
||
| 340 | } |
||
| 341 | break; |
||
| 342 | } |
||
| 343 | } |
||
| 344 | if ( |
||
| 345 | empty($page1Link) |
||
| 346 | && empty($page2Link) |
||
| 347 | ) { |
||
| 348 | $this->logger->warning('File not found in fileGrps "' . $this->extConf['fileGrpDownload'] . '"'); |
||
| 349 | } |
||
| 350 | |||
| 351 | if (!empty($page1Link)) { |
||
| 352 | $pageLinkArray[0] = $page1Link; |
||
| 353 | } |
||
| 354 | if (!empty($page2Link)) { |
||
| 355 | $pageLinkArray[1] = $page2Link; |
||
| 356 | } |
||
| 357 | return $pageLinkArray; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Get work's download link |
||
| 362 | * |
||
| 363 | * @access protected |
||
| 364 | * |
||
| 365 | * @return string Link to downloadable work |
||
| 366 | */ |
||
| 367 | protected function getWorkLink() |
||
| 368 | { |
||
| 369 | $workLink = ''; |
||
| 370 | $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']); |
||
| 371 | // Get work link. |
||
| 372 | while ($fileGrpDownload = array_shift($fileGrpsDownload)) { |
||
| 373 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload])) { |
||
| 374 | $workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload]); |
||
| 375 | break; |
||
| 376 | } else { |
||
| 377 | $details = $this->doc->getLogicalStructure($this->doc->toplevelId); |
||
| 378 | if (!empty($details['files'][$fileGrpDownload])) { |
||
| 379 | $workLink = $this->doc->getFileLocation($details['files'][$fileGrpDownload]); |
||
| 380 | break; |
||
| 381 | } |
||
| 382 | } |
||
| 383 | } |
||
| 384 | if (!empty($workLink)) { |
||
| 385 | $workLink = $workLink; |
||
| 386 | } else { |
||
| 387 | $this->logger->warning('File not found in fileGrps "' . $this->extConf['fileGrpDownload'] . '"'); |
||
| 388 | } |
||
| 389 | return $workLink; |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Renders the searchInDocument tool |
||
| 394 | * @param $requestData |
||
| 395 | * @return void |
||
| 396 | */ |
||
| 397 | public function searchindocumenttool($requestData) |
||
| 398 | { |
||
| 399 | if ( |
||
| 400 | $this->doc === null |
||
| 401 | || $this->doc->numPages < 1 |
||
| 402 | || empty($this->extConf['fileGrpFulltext']) |
||
| 403 | || empty($this->settings['solrcore']) |
||
| 404 | ) { |
||
| 405 | // Quit without doing anything if required variables are not set. |
||
| 406 | return; |
||
| 407 | } else { |
||
| 408 | if (!empty($requestData['logicalPage'])) { |
||
| 409 | $requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
||
| 410 | // The logical page parameter should not appear again |
||
| 411 | unset($requestData['logicalPage']); |
||
| 412 | } |
||
| 413 | // Set default values if not set. |
||
| 414 | // $requestData['page'] may be integer or string (physical structure @ID) |
||
| 415 | if ( |
||
| 416 | (int) $requestData['page'] > 0 |
||
| 417 | || empty($requestData['page']) |
||
| 418 | ) { |
||
| 419 | $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
||
| 420 | } else { |
||
| 421 | $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
||
| 422 | } |
||
| 423 | } |
||
| 424 | |||
| 425 | // Quit if no fulltext file is present |
||
| 426 | $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->settings['fileGrpFulltext']); |
||
| 427 | while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
||
| 428 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext])) { |
||
| 429 | $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpFulltext]; |
||
| 430 | break; |
||
| 431 | } |
||
| 432 | } |
||
| 433 | if (empty($fullTextFile)) { |
||
| 434 | return; |
||
| 435 | } |
||
| 436 | |||
| 437 | // Fill markers. |
||
| 438 | $viewArray = [ |
||
| 439 | 'ACTION_URL' => $this->getActionUrl(), |
||
| 440 | 'LABEL_QUERY_URL' => $this->settings['queryInputName'], |
||
| 441 | 'LABEL_START' => $this->settings['startInputName'], |
||
| 442 | 'LABEL_ID' => $this->settings['idInputName'], |
||
| 443 | 'LABEL_PAGE_URL' => $this->settings['pageInputName'], |
||
| 444 | 'LABEL_HIGHLIGHT_WORD' => $this->settings['highlightWordInputName'], |
||
| 445 | 'LABEL_ENCRYPTED' => $this->settings['encryptedInputName'], |
||
| 446 | 'CURRENT_DOCUMENT' => $this->getCurrentDocumentId(), |
||
| 447 | 'SOLR_ENCRYPTED' => $this->getEncryptedCoreName() ? : '' |
||
| 448 | ]; |
||
| 449 | |||
| 450 | $this->view->assign('searchInDocument', $viewArray); |
||
| 451 | } |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Get the action url for search form |
||
| 455 | * |
||
| 456 | * @access protected |
||
| 457 | * |
||
| 458 | * @return string with action url for search form |
||
| 459 | */ |
||
| 460 | protected function getActionUrl() |
||
| 474 | } |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Get current document id |
||
| 478 | * |
||
| 479 | * @access protected |
||
| 480 | * |
||
| 481 | * @return string with current document id |
||
| 482 | */ |
||
| 483 | protected function getCurrentDocumentId() |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Get the encrypted Solr core name |
||
| 502 | * |
||
| 503 | * @access protected |
||
| 504 | * |
||
| 505 | * @return string with encrypted core name |
||
| 506 | */ |
||
| 507 | protected function getEncryptedCoreName() |
||
| 518 |
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.