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