| Conditions | 15 |
| Paths | 6 |
| Total Lines | 36 |
| Code Lines | 25 |
| Lines | 14 |
| Ratio | 38.89 % |
| Changes | 3 | ||
| 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 |
||
| 21 | function renderNav($offset = 5) |
||
| 22 | { |
||
| 23 | $ret = ''; |
||
| 24 | if ( $this->total <= $this->perpage ) { |
||
| 25 | return $ret; |
||
| 26 | } |
||
| 27 | $total_pages = ceil($this->total / $this->perpage); |
||
| 28 | if ( $total_pages > 1 ) { |
||
| 29 | $prev = $this->current - $this->perpage; |
||
| 30 | if ( $prev >= 0 ) { |
||
| 31 | $ret .= '<a href="' . $this->url . $prev . '"><u>«</u></a> '; |
||
| 32 | } |
||
| 33 | $counter = 1; |
||
| 34 | $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage)); |
||
| 35 | View Code Duplication | while ( $counter <= $total_pages ) { |
|
| 36 | if ( $counter == $current_page ) { |
||
| 37 | $ret .= '<strong>(' . $counter . ')</strong> '; |
||
| 38 | } elseif ( ($counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) { |
||
| 39 | if ( $counter == $total_pages && $current_page < $total_pages - $offset ) { |
||
| 40 | $ret .= '... '; |
||
| 41 | } |
||
| 42 | $ret .= '<a href="' . $this->url . (($counter - 1) * $this->perpage) . '">' . $counter . '</a> '; |
||
| 43 | if ( $counter == 1 && $current_page > 1 + $offset ) { |
||
| 44 | $ret .= '... '; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | $counter++; |
||
| 48 | } |
||
| 49 | $next = $this->current + $this->perpage; |
||
| 50 | if ( $this->total > $next ) { |
||
| 51 | $ret .= '<a href="' . $this->url . $next . '"><u>»</u></a> '; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | return $ret; |
||
| 56 | } |
||
| 57 | |||
| 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.