| Conditions | 15 |
| Paths | 6 |
| Total Lines | 36 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 43 | public function renderNav($offset = 5) |
||
| 44 | { |
||
| 45 | $ret = ''; |
||
| 46 | if ($this->total <= $this->perpage) { |
||
| 47 | return $ret; |
||
| 48 | } |
||
| 49 | $total_pages = ceil($this->total / $this->perpage); |
||
| 50 | if ($total_pages > 1) { |
||
| 51 | $prev = $this->current - $this->perpage; |
||
| 52 | if ($prev >= 0) { |
||
| 53 | $ret .= '<a href="' . $this->url . $prev . '"><u>«</u></a> '; |
||
| 54 | } |
||
| 55 | $counter = 1; |
||
| 56 | $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage); |
||
| 57 | while ($counter <= $total_pages) { |
||
| 58 | if ($counter == $current_page) { |
||
| 59 | $ret .= '<strong>(' . $counter . ')</strong> '; |
||
| 60 | } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || 1 == $counter |
||
| 61 | || $counter == $total_pages) { |
||
| 62 | if ($counter == $total_pages && $current_page < $total_pages - $offset) { |
||
| 63 | $ret .= '... '; |
||
| 64 | } |
||
| 65 | $ret .= '<a href="' . $this->url . (($counter - 1) * $this->perpage) . '">' . $counter . '</a> '; |
||
| 66 | if (1 == $counter && $current_page > 1 + $offset) { |
||
| 67 | $ret .= '... '; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | ++$counter; |
||
| 71 | } |
||
| 72 | $next = $this->current + $this->perpage; |
||
| 73 | if ($this->total > $next) { |
||
| 74 | $ret .= '<a href="' . $this->url . $next . '"><u>»</u></a> '; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $ret; |
||
| 79 | } |
||
| 159 |