Skip to content

Commit

Permalink
to positive args
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonvleite committed Jan 18, 2019
1 parent c5ffd75 commit a01ea13
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public function __construct(string $link = null, string $title = null, array $fi
*/
public function pager(int $rows, int $limit = 10, int $page = null, int $range = 3, string $hash = null): void
{
$this->page = ($page >= 1 ? $page : 1);
$this->rows = ($rows >= 1 ? $rows : 1);
$this->limit = ($limit >= 1 ? $limit : 1);
$this->range = ($range >= 1 ? $range : 1);
$this->page = $this->toPositive($page);
$this->rows = $this->toPositive($rows);
$this->limit = $this->toPositive($limit);
$this->range = $this->toPositive($range);

$this->offset = (($page * $limit) - $limit >= 0 ? ($page * $limit) - $limit : 0);
$this->hash = ($hash ? "#{$hash}" : null);
Expand Down Expand Up @@ -152,4 +152,13 @@ private function afterPages(): ?string

return $after;
}

/**
* @param $number
* @return int
*/
private function toPositive($number): int
{
return ($number >= 1 ? $number : 1);
}
}

0 comments on commit a01ea13

Please sign in to comment.