| Conditions | 18 |
| Paths | 41 |
| Total Lines | 85 |
| Code Lines | 58 |
| 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 |
||
| 122 | public function page_links($path='?',$ext=null) |
||
| 123 | { |
||
| 124 | $adjacents = "2"; |
||
| 125 | $prev = $this->_page - 1; |
||
| 126 | $next = $this->_page + 1; |
||
| 127 | $lastpage = ceil($this->_totalRows/$this->_perPage); |
||
| 128 | $lpm1 = $lastpage - 1; |
||
| 129 | $pagination = ""; |
||
| 130 | if($lastpage > 1) |
||
| 131 | { |
||
| 132 | if($ext==null){ |
||
| 133 | $ext=$this->getParam(); |
||
| 134 | } |
||
| 135 | $pagination .= "<ul class='pager'>"; |
||
| 136 | if ($this->_page > 1) |
||
| 137 | $pagination.= "<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
||
| 138 | else |
||
| 139 | $pagination.= "<li class='disabled previous'><span class='disabled'><<</span></li>"; |
||
| 140 | |||
| 141 | if ($lastpage < 7 + ($adjacents * 2)) |
||
| 142 | { |
||
| 143 | for ($counter = 1; $counter <= $lastpage; $counter++) |
||
| 144 | { |
||
| 145 | if ($counter == $this->_page) |
||
| 146 | $pagination.= "<li class='current'><span>$counter</span></li>"; |
||
| 147 | else |
||
| 148 | $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | elseif($lastpage > 5 + ($adjacents * 2)) |
||
| 152 | { |
||
| 153 | if($this->_page < 1 + ($adjacents * 2)) |
||
| 154 | { |
||
| 155 | for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) |
||
| 156 | { |
||
| 157 | if ($counter == $this->_page) |
||
| 158 | $pagination.= "<li class='current'><span>$counter</span></li>"; |
||
| 159 | else |
||
| 160 | $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
||
| 161 | } |
||
| 162 | $pagination.= "..."; |
||
| 163 | $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
||
| 164 | $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
||
| 165 | } |
||
| 166 | elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
||
| 167 | { |
||
| 168 | $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
||
| 169 | $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
||
| 170 | $pagination.= "..."; |
||
| 171 | for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
||
| 172 | { |
||
| 173 | if ($counter == $this->_page) |
||
| 174 | $pagination.= "<li class='current'><span>$counter</span></li>"; |
||
| 175 | else |
||
| 176 | $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
||
| 177 | } |
||
| 178 | $pagination.= ".."; |
||
| 179 | $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
||
| 180 | $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
||
| 181 | } |
||
| 182 | else |
||
| 183 | { |
||
| 184 | $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
||
| 185 | $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
||
| 186 | $pagination.= ".."; |
||
| 187 | for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
||
| 188 | { |
||
| 189 | if ($counter == $this->_page) |
||
| 190 | $pagination.= "<li class='current'><span>$counter</span></li>"; |
||
| 191 | else |
||
| 192 | $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
||
| 193 | } |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | if ($this->_page < $counter - 1) |
||
| 198 | $pagination.= "<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
||
| 199 | else |
||
| 200 | $pagination.= "<li class='next disabled'><span class='disabled'>>></span></li>"; |
||
| 201 | $pagination.= "</ul>\n"; |
||
| 202 | } |
||
| 203 | |||
| 204 | |||
| 205 | return $pagination; |
||
| 206 | } |
||
| 207 | } |
This check marks private properties in classes that are never used. Those properties can be removed.