| Conditions | 15 |
| Paths | 6 |
| Total Lines | 38 |
| Code Lines | 26 |
| Lines | 14 |
| Ratio | 36.84 % |
| 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 |
||
| 36 | public function renderNav($offset = 5) |
||
| 37 | { |
||
| 38 | $ret = ''; |
||
| 39 | if ($this->total <= $this->perpage) { |
||
| 40 | return $ret; |
||
| 41 | } |
||
| 42 | $total_pages = ceil($this->total / $this->perpage); |
||
| 43 | if ($total_pages > 1) { |
||
| 44 | $prev = $this->current - $this->perpage; |
||
| 45 | if ($prev >= 0) { |
||
| 46 | $ret .= '<a href="' . $this->url . $prev . '"><u>«</u></a> '; |
||
| 47 | } |
||
| 48 | $counter = 1; |
||
| 49 | $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage); |
||
| 50 | View Code Duplication | while ($counter <= $total_pages) { |
|
| 51 | if ($counter == $current_page) { |
||
| 52 | $ret .= '<strong>(' . $counter . ')</strong> '; |
||
| 53 | } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 |
||
| 54 | || $counter == $total_pages |
||
| 55 | ) { |
||
| 56 | if ($counter == $total_pages && $current_page < $total_pages - $offset) { |
||
| 57 | $ret .= '... '; |
||
| 58 | } |
||
| 59 | $ret .= '<a href="' . $this->url . (($counter - 1) * $this->perpage) . '">' . $counter . '</a> '; |
||
| 60 | if ($counter == 1 && $current_page > 1 + $offset) { |
||
| 61 | $ret .= '... '; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | $counter++; |
||
| 65 | } |
||
| 66 | $next = $this->current + $this->perpage; |
||
| 67 | if ($this->total > $next) { |
||
| 68 | $ret .= '<a href="' . $this->url . $next . '"><u>»</u></a> '; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return $ret; |
||
| 73 | } |
||
| 74 | |||
| 154 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.