| Conditions | 15 |
| Paths | 6 |
| Total Lines | 40 |
| Code Lines | 28 |
| Lines | 14 |
| Ratio | 35 % |
| 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 |
||
| 113 | public function renderImageNav($offset = 5) |
||
| 114 | { |
||
| 115 | if ($this->total < $this->perpage) { |
||
| 116 | return; |
||
| 117 | } |
||
| 118 | $total_pages = ceil($this->total / $this->perpage); |
||
| 119 | $ret = ''; |
||
| 120 | if ($total_pages > 1) { |
||
| 121 | $ret = '<table><tr>'; |
||
| 122 | $prev = $this->current - $this->perpage; |
||
| 123 | if ($prev >= 0) { |
||
| 124 | $ret .= '<td class="pagneutral"><a href="' . $this->url . $prev . '"><</a></td><td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt=""></td>'; |
||
| 125 | } |
||
| 126 | $counter = 1; |
||
| 127 | $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage); |
||
| 128 | View Code Duplication | while ($counter <= $total_pages) { |
|
| 129 | if ($counter == $current_page) { |
||
| 130 | $ret .= '<td class="pagact"><b>' . $counter . '</b></td>'; |
||
| 131 | } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 |
||
| 132 | || $counter == $total_pages |
||
| 133 | ) { |
||
| 134 | if ($counter == $total_pages && $current_page < $total_pages - $offset) { |
||
| 135 | $ret .= '<td class="paginact">...</td>'; |
||
| 136 | } |
||
| 137 | $ret .= '<td class="paginact"><a href="' . $this->url . (($counter - 1) * $this->perpage) . '">' . $counter . '</a></td>'; |
||
| 138 | if ($counter == 1 && $current_page > 1 + $offset) { |
||
| 139 | $ret .= '<td class="paginact">...</td>'; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | $counter++; |
||
| 143 | } |
||
| 144 | $next = $this->current + $this->perpage; |
||
| 145 | if ($this->total > $next) { |
||
| 146 | $ret .= '<td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt=""></td><td class="pagneutral"><a href="' . $this->url . $next . '">></a></td>'; |
||
| 147 | } |
||
| 148 | $ret .= '</tr></table>'; |
||
| 149 | } |
||
| 150 | |||
| 151 | return $ret; |
||
| 152 | } |
||
| 153 | } |
||
| 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.