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 | 117 |
| Code Lines | 73 |
| 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 | $sort = $this->requestData['sort']; |
||
| 325 | $pointer = $this->requestData['pointer']; |
||
| 326 | $logicalPage = $this->requestData['logicalPage']; |
||
| 327 | |||
| 328 | $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 329 | |||
| 330 | // Load the list. |
||
| 331 | $this->list = GeneralUtility::makeInstance(DocumentList::class); |
||
| 332 | $currentEntry = $pointer * $this->settings['limit']; |
||
| 333 | $lastEntry = ($pointer + 1) * $this->settings['limit']; |
||
| 334 | |||
| 335 | // Check if it's a list of database records or Solr documents. |
||
| 336 | if ( |
||
| 337 | !empty($this->list->metadata['options']['source']) |
||
| 338 | && $this->list->metadata['options']['source'] == 'collection' |
||
| 339 | && ((!empty($sort['order']) && $sort['order'] != $this->list->metadata['options']['order']) |
||
| 340 | || (isset($sort['orderBy']) && $sort['orderBy'] != $this->list->metadata['options']['orderBy'])) |
||
| 341 | ) { |
||
| 342 | // Order list by given field. |
||
| 343 | $this->list->sort($sort['order'], $sort['orderBy'] == 'asc' ? true : false); |
||
| 344 | // Update list's metadata. |
||
| 345 | $listMetadata = $this->list->metadata; |
||
| 346 | $listMetadata['options']['order'] = $sort['order']; |
||
| 347 | $listMetadata['options']['orderBy'] = $sort['orderBy']; |
||
| 348 | $this->list->metadata = $listMetadata; |
||
| 349 | // Save updated list. |
||
| 350 | $this->list->save(); |
||
| 351 | // Reset pointer. |
||
| 352 | $pointer = 0; |
||
| 353 | } elseif (!empty($this->list->metadata['options']['source']) && $this->list->metadata['options']['source'] == 'search') { |
||
| 354 | // Update list's metadata |
||
| 355 | $listMetadata = $this->list->metadata; |
||
| 356 | // Sort the list if applicable. |
||
| 357 | if ((!empty($sort['order']) && $sort['order'] != $listMetadata['options']['order']) |
||
| 358 | || (isset($sort['orderBy']) && $sort['orderBy'] != $listMetadata['options']['orderBy']) |
||
| 359 | ) { |
||
| 360 | // Update list's metadata. |
||
| 361 | $listMetadata['options']['params']['sort'] = [$sort['order'] . "_sorting" => (bool) $sort['asc'] ? 'asc' : 'desc']; |
||
| 362 | $listMetadata['options']['order'] = $sort['order']; |
||
| 363 | $listMetadata['options']['orderBy'] = $sort['orderBy']; |
||
| 364 | // Reset pointer. |
||
| 365 | $pointer = 0; |
||
| 366 | } |
||
| 367 | // Set some query parameters |
||
| 368 | $listMetadata['options']['params']['start'] = $currentEntry; |
||
| 369 | $listMetadata['options']['params']['rows'] = $this->settings['limit']; |
||
| 370 | // Search only if the query params have changed. |
||
| 371 | if ($listMetadata['options']['params'] != $this->list->metadata['options']['params']) { |
||
| 372 | // Instantiate search object. |
||
| 373 | $solr = Solr::getInstance($this->list->metadata['options']['core']); |
||
| 374 | if (!$solr->ready) { |
||
| 375 | $this->logger->error('Apache Solr not available'); |
||
| 376 | } |
||
| 377 | // Set search parameters. |
||
| 378 | $solr->cPid = $listMetadata['options']['pid']; |
||
| 379 | $solr->params = $listMetadata['options']['params']; |
||
| 380 | // Perform search. |
||
| 381 | $this->list = $solr->search(); |
||
| 382 | } |
||
| 383 | $this->list->metadata = $listMetadata; |
||
| 384 | // Save updated list. |
||
| 385 | $this->list->save(); |
||
| 386 | $currentEntry = 0; |
||
| 387 | $lastEntry = $this->settings['limit']; |
||
| 388 | } |
||
| 389 | |||
| 390 | // Set some variable defaults. |
||
| 391 | if (!empty($pointer) && (($pointer * $this->settings['limit']) + 1) <= $this->list->metadata['options']['numberOfToplevelHits']) { |
||
| 392 | $pointer = max(intval($pointer), 0); |
||
| 393 | } else { |
||
| 394 | $pointer = 0; |
||
| 395 | } |
||
| 396 | |||
| 397 | // Load metadata configuration. |
||
| 398 | $this->loadConfig(); |
||
| 399 | for ($currentEntry, $lastEntry; $currentEntry < $lastEntry; $currentEntry++) { |
||
| 400 | if (empty($this->list[$currentEntry])) { |
||
| 401 | break; |
||
| 402 | } else { |
||
| 403 | $this->getEntry($currentEntry); |
||
| 404 | } |
||
| 405 | } |
||
| 406 | |||
| 407 | if ($currentEntry) { |
||
| 408 | $currentEntry = ($pointer * $this->settings['limit']) + 1; |
||
| 409 | $lastEntry = ($pointer * $this->settings['limit']) + $this->settings['limit']; |
||
| 410 | } |
||
| 411 | |||
| 412 | // Pagination of Results |
||
| 413 | // pass the currentPage to the fluid template to calculate current index of search result |
||
| 414 | if (empty($this->requestData['@widget_0'])) { |
||
| 415 | $widgetPage = ['currentPage' => 1]; |
||
| 416 | } else { |
||
| 417 | $widgetPage = $this->requestData['@widget_0']; |
||
| 418 | } |
||
| 419 | |||
| 420 | // convert documentList to array --> use widget.pagination viewhelper |
||
| 421 | $documentList = []; |
||
| 422 | foreach ($this->list as $listElement) { |
||
| 423 | $documentList[] = $listElement; |
||
| 424 | } |
||
| 425 | $this->view->assign('widgetPage', $widgetPage); |
||
| 426 | $this->view->assign('documentList', $this->list); |
||
| 427 | $this->view->assign('documentListArray', $documentList); |
||
| 428 | $this->view->assign('metadataList', $this->metadataList); |
||
| 429 | $this->view->assign('metadataConfig', $this->metadata); |
||
| 430 | $this->view->assign('currentEntry', $currentEntry); |
||
| 431 | $this->view->assign('lastEntry', $lastEntry); |
||
| 432 | $this->view->assign('sortables', $this->sortables); |
||
| 433 | $this->view->assign('logicalPage', $logicalPage); |
||
| 434 | $this->view->assign( |
||
| 435 | 'maxPages', |
||
| 436 | intval(ceil($this->list->metadata['options']['numberOfToplevelHits'] / $this->settings['limit'])) |
||
| 437 | ); |
||
| 438 | $this->view->assign('forceAbsoluteUrl', !empty($this->extConf['forceAbsoluteUrl']) ? 1 : 0); |
||
| 439 | } |
||
| 441 |