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