| Conditions | 43 |
| Paths | > 20000 |
| Total Lines | 109 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 306 | public function calculate() |
||
| 307 | { |
||
| 308 | $this->pagination = ""; |
||
| 309 | $this->calculate = true; |
||
| 310 | $error = false; |
||
| 311 | |||
| 312 | if (!empty($this->urlF) && is_scalar($this->urlF) && $this->urlF != '%' && strpos($this->target, |
||
| 313 | $this->urlF) === false |
||
| 314 | ) { |
||
| 315 | //Es necesario especificar el comodin para sustituir |
||
| 316 | $error = true; |
||
| 317 | } elseif (!empty($this->urlF) && is_scalar($this->urlF) && $this->urlF == '%' && strpos($this->target, |
||
| 318 | $this->urlF) === false |
||
| 319 | ) { |
||
| 320 | $error = true; |
||
| 321 | } |
||
| 322 | |||
| 323 | if ($this->total_pages < 0) { |
||
| 324 | $error = true; |
||
| 325 | } |
||
| 326 | if (!is_int($this->limit)) { |
||
| 327 | $error = true; |
||
| 328 | } |
||
| 329 | if ($error) { |
||
| 330 | return false; |
||
| 331 | } |
||
| 332 | |||
| 333 | $counter = 0; |
||
| 334 | |||
| 335 | /* Setup page vars for display. */ |
||
| 336 | $prev = ($this->page <= 1) ? 0 : $this->page - 1; //previous page is page - 1 |
||
| 337 | $next = (($this->page == $this->total_pages) ? 0 : ($this->page + 1)); //next page is page + 1 |
||
| 338 | $lastpage = $this->total_pages; |
||
| 339 | if ($this->limit > 1 && $lastpage > $this->limit) { |
||
| 340 | $lastpage = $this->limit; |
||
| 341 | } |
||
| 342 | $lpm1 = $lastpage - 1; //last page minus 1 |
||
| 343 | |||
| 344 | /* |
||
| 345 | Now we apply our rules and draw the pagination object. |
||
| 346 | We're actually saving the code to a variable in case we want to draw it more than once. |
||
| 347 | */ |
||
| 348 | if ($lastpage > 1) { |
||
| 349 | if ($this->page) { |
||
| 350 | if ($this->page > 1) { |
||
| 351 | $this->pagination .= $this->firstT ? $this->renderItemTPL($this->firstT, 0) : ''; |
||
| 352 | $this->pagination .= $this->prevT ? $this->renderItemTPL($this->prevT, $prev) : ''; |
||
| 353 | } else { |
||
| 354 | $this->pagination .= $this->firstI ? $this->renderItemTPL($this->firstI, 0) : ''; |
||
| 355 | $this->pagination .= $this->prevI ? $this->renderItemTPL($this->prevI, $prev) : ''; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | //pages |
||
| 359 | if ($lastpage < 7 + ($this->adjacents * 2)) { //not enough pages to bother breaking it up |
||
| 360 | for ($counter = 1; $counter <= $lastpage; $counter++) { |
||
| 361 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
||
| 362 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
||
| 363 | } |
||
| 364 | } elseif ($lastpage > 5 + ($this->adjacents * 2)) { //enough pages to hide some |
||
| 365 | //close to beginning; only hide later pages |
||
| 366 | if ($this->page <= 2 + ($this->adjacents * 2)) { |
||
| 367 | for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++) { |
||
| 368 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
||
| 369 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
||
| 370 | } |
||
| 371 | $this->pagination .= $this->renderItemTPL($this->dotsT, $counter); |
||
| 372 | $this->pagination .= $this->renderItemTPL($this->numberT, $lpm1); |
||
| 373 | $this->pagination .= $this->renderItemTPL($this->numberT, $lastpage); |
||
| 374 | } //in middle; hide some front and some back |
||
| 375 | elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) { |
||
| 376 | $this->pagination .= $this->renderItemTPL($this->numberT, 1); |
||
| 377 | $this->pagination .= $this->renderItemTPL($this->numberT, 2); |
||
| 378 | $this->pagination .= $this->renderItemTPL($this->dotsT, 3); |
||
| 379 | |||
| 380 | for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++) { |
||
| 381 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
||
| 382 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
||
| 383 | } |
||
| 384 | $this->pagination .= $this->renderItemTPL($this->dotsT, $counter); |
||
| 385 | $this->pagination .= $this->renderItemTPL($this->numberT, $lpm1); |
||
| 386 | $this->pagination .= $this->renderItemTPL($this->numberT, $lastpage); |
||
| 387 | } //close to end; only hide early pages |
||
| 388 | else { |
||
| 389 | $this->pagination .= $this->renderItemTPL($this->numberT, 1); |
||
| 390 | $this->pagination .= $this->renderItemTPL($this->numberT, 2); |
||
| 391 | $this->pagination .= $this->renderItemTPL($this->dotsT, 3); |
||
| 392 | |||
| 393 | for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++) { |
||
| 394 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
||
| 395 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | } |
||
| 399 | if ($this->page) { |
||
| 400 | if ($this->page < $counter - 1) { |
||
| 401 | $this->pagination .= $this->nextT ? $this->renderItemTPL($this->nextT, $next) : ''; |
||
| 402 | $this->pagination .= $this->lastT ? $this->renderItemTPL($this->lastT, $lastpage) : ''; |
||
| 403 | } else { |
||
| 404 | $this->pagination .= $this->nextI ? $this->renderItemTPL($this->nextI, $next) : ''; |
||
| 405 | $this->pagination .= $this->lastI ? $this->renderItemTPL($this->lastI, $lastpage) : ''; |
||
| 406 | } |
||
| 407 | |||
| 408 | if ($this->showCounter) { |
||
| 409 | $this->pagination .= "<div class=\"pagination_data\">($this->total_pages Pages)</div>"; |
||
| 410 | } |
||
| 411 | } |
||
| 412 | } |
||
| 413 | |||
| 414 | return true; |
||
| 415 | } |
||
| 427 |