| Conditions | 10 |
| Paths | 146 |
| Total Lines | 61 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 57 | public function render() |
||
| 58 | { |
||
| 59 | $maximumNumberOfResultPages = $this->arguments['maximumNumberOfResultPages']; |
||
| 60 | $numberOfResults = $this->arguments['numberOfResults']; |
||
| 61 | $resultsPerPage = $this->arguments['resultsPerPage']; |
||
| 62 | $currentPage = $this->arguments['currentPage']; |
||
| 63 | $freeIndexUid = $this->arguments['freeIndexUid']; |
||
| 64 | |||
| 65 | if ($resultsPerPage <= 0) { |
||
| 66 | $resultsPerPage = 10; |
||
| 67 | } |
||
| 68 | $pageCount = (int)ceil($numberOfResults / $resultsPerPage); |
||
| 69 | // only show the result browser if more than one page is needed |
||
| 70 | if ($pageCount === 1) { |
||
| 71 | return ''; |
||
| 72 | } |
||
| 73 | |||
| 74 | // Check if $currentPage is in range |
||
| 75 | $currentPage = MathUtility::forceIntegerInRange($currentPage, 0, $pageCount - 1); |
||
| 76 | |||
| 77 | $content = ''; |
||
| 78 | // prev page |
||
| 79 | // show on all pages after the 1st one |
||
| 80 | if ($currentPage > 0) { |
||
| 81 | $label = LocalizationUtility::translate('displayResults.previous', 'IndexedSearch'); |
||
| 82 | $content .= '<li>' . $this->makecurrentPageSelector_link($label, $currentPage - 1, $freeIndexUid) . '</li>'; |
||
| 83 | } |
||
| 84 | // Check if $maximumNumberOfResultPages is in range |
||
| 85 | $maximumNumberOfResultPages = MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, $pageCount, 10); |
||
| 86 | // Assume $currentPage is in the middle and calculate the index limits of the result page listing |
||
| 87 | $minPage = $currentPage - (int)floor($maximumNumberOfResultPages / 2); |
||
| 88 | $maxPage = $minPage + $maximumNumberOfResultPages - 1; |
||
| 89 | // Check if the indexes are within the page limits |
||
| 90 | if ($minPage < 0) { |
||
| 91 | $maxPage -= $minPage; |
||
| 92 | $minPage = 0; |
||
| 93 | } elseif ($maxPage >= $pageCount) { |
||
| 94 | $minPage -= $maxPage - $pageCount + 1; |
||
| 95 | $maxPage = $pageCount - 1; |
||
| 96 | } |
||
| 97 | $pageLabel = LocalizationUtility::translate('displayResults.page', 'IndexedSearch'); |
||
| 98 | for ($a = $minPage; $a <= $maxPage; $a++) { |
||
| 99 | $label = trim($pageLabel . ' ' . ($a + 1)); |
||
| 100 | $label = self::makecurrentPageSelector_link($label, $a, $freeIndexUid); |
||
|
|
|||
| 101 | if ($a === $currentPage) { |
||
| 102 | $content .= '<li class="tx-indexedsearch-browselist-currentPage"><strong>' . $label . '</strong></li>'; |
||
| 103 | } else { |
||
| 104 | $content .= '<li>' . $label . '</li>'; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | // next link |
||
| 108 | if ($currentPage < $pageCount - 1) { |
||
| 109 | $label = LocalizationUtility::translate('displayResults.next', 'IndexedSearch'); |
||
| 110 | $content .= '<li>' . self::makecurrentPageSelector_link($label, $currentPage + 1, $freeIndexUid) . '</li>'; |
||
| 111 | } |
||
| 112 | |||
| 113 | if (!$this->tag->hasAttribute('class')) { |
||
| 114 | $this->tag->addAttribute('class', 'tx-indexedsearch-browsebox'); |
||
| 115 | } |
||
| 116 | $this->tag->setContent($content); |
||
| 117 | return $this->tag->render(); |
||
| 118 | } |
||
| 139 |