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