| Conditions | 22 |
| Paths | 132 |
| Total Lines | 83 |
| Code Lines | 55 |
| Lines | 16 |
| Ratio | 19.28 % |
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 |
||
| 208 | function _getPageLinks($url = '') |
||
| 209 | { |
||
| 210 | //legacy setting... the preferred way to set an option now |
||
| 211 | //is adding it to the constuctor |
||
| 212 | if (!empty($url)) { |
||
| 213 | $this->_path = $url; |
||
| 214 | } |
||
| 215 | |||
| 216 | //If there's only one page, don't display links |
||
| 217 | if ($this->_clearIfVoid && ($this->_totalPages < 2)) { |
||
| 218 | return ''; |
||
| 219 | } |
||
| 220 | |||
| 221 | $links = ''; |
||
| 222 | if ($this->_totalPages > (2 * $this->_delta + 1)) { |
||
| 223 | if ($this->_expanded) { |
||
| 224 | if (($this->_totalPages - $this->_delta) <= $this->_currentPage) { |
||
| 225 | $expansion_before = $this->_currentPage - ($this->_totalPages - $this->_delta); |
||
| 226 | } else { |
||
| 227 | $expansion_before = 0; |
||
| 228 | } |
||
| 229 | for ($i = $this->_currentPage - $this->_delta - $expansion_before; $expansion_before; $expansion_before--, $i++) { |
||
| 230 | $print_separator_flag = ($i != $this->_currentPage + $this->_delta); // && ($i != $this->_totalPages - 1) |
||
| 231 | |||
| 232 | $this->range[$i] = false; |
||
| 233 | $this->_linkData[$this->_urlVar] = $i; |
||
| 234 | $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i) |
||
| 235 | . $this->_spacesBefore |
||
| 236 | . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : ''); |
||
| 237 | } |
||
| 238 | } |
||
| 239 | |||
| 240 | $expansion_after = 0; |
||
| 241 | for ($i = $this->_currentPage - $this->_delta; ($i <= $this->_currentPage + $this->_delta) && ($i <= $this->_totalPages); $i++) { |
||
| 242 | if ($i < 1) { |
||
| 243 | ++$expansion_after; |
||
| 244 | continue; |
||
| 245 | } |
||
| 246 | |||
| 247 | // check when to print separator |
||
| 248 | $print_separator_flag = (($i != $this->_currentPage + $this->_delta) && ($i != $this->_totalPages)); |
||
| 249 | |||
| 250 | View Code Duplication | if ($i == $this->_currentPage) { |
|
| 251 | $this->range[$i] = true; |
||
| 252 | $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost; |
||
| 253 | } else { |
||
| 254 | $this->range[$i] = false; |
||
| 255 | $this->_linkData[$this->_urlVar] = $i; |
||
| 256 | $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i); |
||
| 257 | } |
||
| 258 | $links .= $this->_spacesBefore |
||
| 259 | . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : ''); |
||
| 260 | } |
||
| 261 | |||
| 262 | if ($this->_expanded && $expansion_after) { |
||
| 263 | $links .= $this->_separator . $this->_spacesAfter; |
||
| 264 | for ($i = $this->_currentPage + $this->_delta +1; $expansion_after; $expansion_after--, $i++) { |
||
| 265 | $print_separator_flag = ($expansion_after != 1); |
||
| 266 | $this->range[$i] = false; |
||
| 267 | $this->_linkData[$this->_urlVar] = $i; |
||
| 268 | $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i) |
||
| 269 | . $this->_spacesBefore |
||
| 270 | . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : ''); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | |||
| 274 | } else { |
||
| 275 | //if $this->_totalPages <= (2*Delta+1) show them all |
||
| 276 | for ($i=1; $i<=$this->_totalPages; $i++) { |
||
| 277 | View Code Duplication | if ($i != $this->_currentPage) { |
|
| 278 | $this->range[$i] = false; |
||
| 279 | $this->_linkData[$this->_urlVar] = $i; |
||
| 280 | $links .= $this->_renderLink(str_replace('%d', $i, $this->_altPage), $i); |
||
| 281 | } else { |
||
| 282 | $this->range[$i] = true; |
||
| 283 | $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost; |
||
| 284 | } |
||
| 285 | $links .= $this->_spacesBefore |
||
| 286 | . (($i != $this->_totalPages) ? $this->_separator.$this->_spacesAfter : ''); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | return $links; |
||
| 290 | } |
||
| 291 | |||
| 295 |