We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 25 |
| Paths | 352 |
| Total Lines | 119 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 322 | public function mainAction() |
||
| 323 | { |
||
| 324 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 325 | |||
| 326 | $sort = $requestData['sort']; |
||
| 327 | $pointer = $requestData['pointer']; |
||
| 328 | $logicalPage = $requestData['logicalPage']; |
||
| 329 | |||
| 330 | $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 331 | |||
| 332 | // Load the list. |
||
| 333 | $this->list = GeneralUtility::makeInstance(DocumentList::class); |
||
| 334 | $currentEntry = $pointer * $this->settings['limit']; |
||
| 335 | $lastEntry = ($pointer + 1) * $this->settings['limit']; |
||
| 336 | |||
| 337 | // Check if it's a list of database records or Solr documents. |
||
| 338 | if ( |
||
| 339 | !empty($this->list->metadata['options']['source']) |
||
| 340 | && $this->list->metadata['options']['source'] == 'collection' |
||
| 341 | && ((!empty($sort['order']) && $sort['order'] != $this->list->metadata['options']['order']) |
||
| 342 | || (isset($sort['orderBy']) && $sort['orderBy'] != $this->list->metadata['options']['orderBy'])) |
||
| 343 | ) { |
||
| 344 | // Order list by given field. |
||
| 345 | $this->list->sort($sort['order'], $sort['orderBy'] == 'asc' ? true : false); |
||
| 346 | // Update list's metadata. |
||
| 347 | $listMetadata = $this->list->metadata; |
||
| 348 | $listMetadata['options']['order'] = $sort['order']; |
||
| 349 | $listMetadata['options']['orderBy'] = $sort['orderBy']; |
||
| 350 | $this->list->metadata = $listMetadata; |
||
| 351 | // Save updated list. |
||
| 352 | $this->list->save(); |
||
| 353 | // Reset pointer. |
||
| 354 | $pointer = 0; |
||
| 355 | } elseif (!empty($this->list->metadata['options']['source']) && $this->list->metadata['options']['source'] == 'search') { |
||
| 356 | // Update list's metadata |
||
| 357 | $listMetadata = $this->list->metadata; |
||
| 358 | // Sort the list if applicable. |
||
| 359 | if ((!empty($sort['order']) && $sort['order'] != $listMetadata['options']['order']) |
||
| 360 | || (isset($sort['orderBy']) && $sort['orderBy'] != $listMetadata['options']['orderBy']) |
||
| 361 | ) { |
||
| 362 | // Update list's metadata. |
||
| 363 | $listMetadata['options']['params']['sort'] = [$sort['order'] . "_sorting" => (bool) $sort['asc'] ? 'asc' : 'desc']; |
||
| 364 | $listMetadata['options']['order'] = $sort['order']; |
||
| 365 | $listMetadata['options']['orderBy'] = $sort['orderBy']; |
||
| 366 | // Reset pointer. |
||
| 367 | $pointer = 0; |
||
| 368 | } |
||
| 369 | // Set some query parameters |
||
| 370 | $listMetadata['options']['params']['start'] = $currentEntry; |
||
| 371 | $listMetadata['options']['params']['rows'] = $this->settings['limit']; |
||
| 372 | // Search only if the query params have changed. |
||
| 373 | if ($listMetadata['options']['params'] != $this->list->metadata['options']['params']) { |
||
| 374 | // Instantiate search object. |
||
| 375 | $solr = Solr::getInstance($this->list->metadata['options']['core']); |
||
| 376 | if (!$solr->ready) { |
||
| 377 | $this->logger->error('Apache Solr not available'); |
||
| 378 | } |
||
| 379 | // Set search parameters. |
||
| 380 | $solr->cPid = $listMetadata['options']['pid']; |
||
| 381 | $solr->params = $listMetadata['options']['params']; |
||
| 382 | // Perform search. |
||
| 383 | $this->list = $solr->search(); |
||
| 384 | } |
||
| 385 | $this->list->metadata = $listMetadata; |
||
| 386 | // Save updated list. |
||
| 387 | $this->list->save(); |
||
| 388 | $currentEntry = 0; |
||
| 389 | $lastEntry = $this->settings['limit']; |
||
| 390 | } |
||
| 391 | |||
| 392 | // Set some variable defaults. |
||
| 393 | if (!empty($pointer) && (($pointer * $this->settings['limit']) + 1) <= $this->list->metadata['options']['numberOfToplevelHits']) { |
||
| 394 | $pointer = max(intval($pointer), 0); |
||
| 395 | } else { |
||
| 396 | $pointer = 0; |
||
| 397 | } |
||
| 398 | |||
| 399 | // Load metadata configuration. |
||
| 400 | $this->loadConfig(); |
||
| 401 | for ($currentEntry, $lastEntry; $currentEntry < $lastEntry; $currentEntry++) { |
||
| 402 | if (empty($this->list[$currentEntry])) { |
||
| 403 | break; |
||
| 404 | } else { |
||
| 405 | $this->getEntry($currentEntry); |
||
| 406 | } |
||
| 407 | } |
||
| 408 | |||
| 409 | if ($currentEntry) { |
||
| 410 | $currentEntry = ($pointer * $this->settings['limit']) + 1; |
||
| 411 | $lastEntry = ($pointer * $this->settings['limit']) + $this->settings['limit']; |
||
| 412 | } |
||
| 413 | |||
| 414 | // Pagination of Results |
||
| 415 | // pass the currentPage to the fluid template to calculate current index of search result |
||
| 416 | if (empty($requestData['@widget_0'])) { |
||
| 417 | $widgetPage = ['currentPage' => 1]; |
||
| 418 | } else { |
||
| 419 | $widgetPage = $requestData['@widget_0']; |
||
| 420 | } |
||
| 421 | |||
| 422 | // convert documentList to array --> use widget.pagination viewhelper |
||
| 423 | $documentList = []; |
||
| 424 | foreach ($this->list as $listElement) { |
||
| 425 | $documentList[] = $listElement; |
||
| 426 | } |
||
| 427 | $this->view->assign('widgetPage', $widgetPage); |
||
| 428 | $this->view->assign('documentList', $this->list); |
||
| 429 | $this->view->assign('documentListArray', $documentList); |
||
| 430 | $this->view->assign('metadataList', $this->metadataList); |
||
| 431 | $this->view->assign('metadataConfig', $this->metadata); |
||
| 432 | $this->view->assign('currentEntry', $currentEntry); |
||
| 433 | $this->view->assign('lastEntry', $lastEntry); |
||
| 434 | $this->view->assign('sortables', $this->sortables); |
||
| 435 | $this->view->assign('logicalPage', $logicalPage); |
||
| 436 | $this->view->assign( |
||
| 437 | 'maxPages', |
||
| 438 | intval(ceil($this->list->metadata['options']['numberOfToplevelHits'] / $this->settings['limit'])) |
||
| 439 | ); |
||
| 440 | $this->view->assign('forceAbsoluteUrl', !empty($this->extConf['forceAbsoluteUrl']) ? 1 : 0); |
||
| 441 | } |
||
| 443 |