Conditions | 15 |
Paths | 6 |
Total Lines | 38 |
Code Lines | 27 |
Lines | 14 |
Ratio | 36.84 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 |
||
88 | function renderImageNav($offset = 5) |
||
89 | { |
||
90 | if ( $this->total < $this->perpage ) { |
||
91 | return; |
||
92 | } |
||
93 | $total_pages = ceil($this->total / $this->perpage); |
||
94 | $ret = ''; |
||
95 | if ( $total_pages > 1 ) { |
||
96 | $ret = '<table><tr>'; |
||
97 | $prev = $this->current - $this->perpage; |
||
98 | if ( $prev >= 0 ) { |
||
99 | $ret .= '<td class="pagneutral"><a href="'.$this->url.$prev.'"><</a></td><td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt=""></td>'; |
||
100 | } |
||
101 | $counter = 1; |
||
102 | $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage)); |
||
103 | View Code Duplication | while ( $counter <= $total_pages ) { |
|
104 | if ( $counter == $current_page ) { |
||
105 | $ret .= '<td class="pagact"><b>'.$counter.'</b></td>'; |
||
106 | } elseif ( ($counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) { |
||
107 | if ( $counter == $total_pages && $current_page < $total_pages - $offset ) { |
||
108 | $ret .= '<td class="paginact">...</td>'; |
||
109 | } |
||
110 | $ret .= '<td class="paginact"><a href="'.$this->url.(($counter - 1) * $this->perpage).'">'.$counter.'</a></td>'; |
||
111 | if ( $counter == 1 && $current_page > 1 + $offset ) { |
||
112 | $ret .= '<td class="paginact">...</td>'; |
||
113 | } |
||
114 | } |
||
115 | $counter++; |
||
116 | } |
||
117 | $next = $this->current + $this->perpage; |
||
118 | if ( $this->total > $next ) { |
||
119 | $ret .= '<td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt=""></td><td class="pagneutral"><a href="'.$this->url.$next.'">></a></td>'; |
||
120 | } |
||
121 | $ret .= '</tr></table>'; |
||
122 | } |
||
123 | |||
124 | return $ret; |
||
125 | } |
||
126 | } |
||
127 |
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.