| Conditions | 11 |
| Paths | 385 |
| Total Lines | 39 |
| Code Lines | 22 |
| 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 |
||
| 47 | public function createLinks($list_class) |
||
| 48 | { |
||
| 49 | if ($this->limit == 'all') { |
||
| 50 | return ''; |
||
| 51 | } |
||
| 52 | $links = (isset($_GET['links'])) ? $_GET['links'] : $this->total_result; |
||
| 53 | |||
| 54 | $last = $this->totalpage; |
||
| 55 | |||
| 56 | $start = (($this->page - $links) > 0) ? $this : 1; |
||
| 57 | $end = (($this->page + $links) < $last) ? $this->page + $links : $last; |
||
| 58 | |||
| 59 | $html = '<ul class="' . $list_class . '">'; |
||
| 60 | |||
| 61 | $class = ($this->page == 1) ? "disabled" : ""; |
||
| 62 | $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . '&page=' . ($this->page - 1) . '">«</a></li>'; |
||
| 63 | |||
| 64 | |||
| 65 | if ($start > 1) { |
||
| 66 | $html .= '<li><a href="?limit=' . $this->limit . '&page=1">1</a></li>'; |
||
| 67 | $html .= '<li class="disabled"><span>...</span></li>'; |
||
| 68 | } |
||
| 69 | |||
| 70 | for ($i = $start; $i <= $end; $i++) { |
||
| 71 | $class = ($this->page == $i) ? "active" : ""; |
||
| 72 | $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . "&page=$i" . '">' . $i . '</a></li>'; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($end < $last) { |
||
| 76 | $html .= '<li class="disabled"><span>...</span></li>'; |
||
| 77 | $html .= '<li><a class="page-link" href="?limit=' . $this->limit . '&page=' . $last . '">' . $last . '</a></li>'; |
||
| 78 | } |
||
| 79 | |||
| 80 | $class = ($this->page == $last) ? "disabled" : ""; |
||
| 81 | $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . '&page=' . ($this->page + 1) . '">»</a></li>'; |
||
| 82 | |||
| 83 | $html .= '</ul>'; |
||
| 84 | |||
| 85 | return $html; |
||
| 86 | } |
||
| 88 |