| Conditions | 9 |
| Paths | 81 |
| Total Lines | 76 |
| Code Lines | 29 |
| 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 |
||
| 53 | public function renderPagingHeader() |
||
| 54 | { |
||
| 55 | $count = $this->count(); |
||
| 56 | if ($count <= $this->maxPerPage ) |
||
| 57 | { |
||
| 58 | return 'count : ' . $this->count() . '<br>'; |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($this->currentPage == 0) $this->currentPage = 1; |
||
| 62 | |||
| 63 | $numPages = intdiv($count , $this->maxPerPage); |
||
| 64 | if ($count % $this->maxPerPage != 0 ) $numPages++; |
||
| 65 | |||
| 66 | $html = '<div class="pagination-control" role="navigation">'; |
||
| 67 | $html .= '<ul class="nav tab-nav">'; |
||
| 68 | if ($this->currentPage <=1) |
||
| 69 | { |
||
| 70 | $html .= ' |
||
| 71 | <li class="nav-item disabled" aria-hidden="true"> |
||
| 72 | <span class="previous-page"> |
||
| 73 | <span class="sr-only">Previous page</span> |
||
| 74 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
||
| 75 | </span> |
||
| 76 | </li> |
||
| 77 | '; |
||
| 78 | } |
||
| 79 | else |
||
| 80 | { |
||
| 81 | $html .= ' |
||
| 82 | <li class="nav-item"> |
||
| 83 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
||
| 84 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
||
| 85 | </a> |
||
| 86 | </li> |
||
| 87 | '; |
||
| 88 | } |
||
| 89 | |||
| 90 | for ($i=1; $i <= $numPages ; $i++) |
||
| 91 | { |
||
| 92 | $active = ($this->currentPage == $i) ? 'active' : ''; |
||
| 93 | $first = ($i-1)*$this->maxPerPage+1; |
||
| 94 | $last = $i * $this->maxPerPage; |
||
| 95 | if ($last > $count) $last = $count; |
||
| 96 | $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
||
| 97 | $html .= '<li class="' . $active . ' nav-item"> |
||
| 98 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
||
| 99 | '.$i.' |
||
| 100 | </a> |
||
| 101 | </li>'; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($this->currentPage == $numPages) |
||
| 105 | { |
||
| 106 | $html .= ' |
||
| 107 | <li class="nav-item disabled" aria-hidden="true"> |
||
| 108 | <span class="previous-page"> |
||
| 109 | <span class="sr-only">Previous page</span> |
||
| 110 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
||
| 111 | </span> |
||
| 112 | </li> |
||
| 113 | '; |
||
| 114 | } |
||
| 115 | else |
||
| 116 | { |
||
| 117 | $html .= ' |
||
| 118 | <li class="nav-item"> |
||
| 119 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
||
| 120 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
||
| 121 | </a> |
||
| 122 | </li> |
||
| 123 | '; |
||
| 124 | } |
||
| 125 | |||
| 126 | $html .= '</ul> </div>'; |
||
| 127 | |||
| 128 | return $html; |
||
| 129 | } |
||
| 138 | } |