Total Complexity | 7 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class Pagination |
||
9 | { |
||
10 | const MIN_PAGE_NUMBER = 1; |
||
11 | const MIN_PAGE_LIMIT = 1; |
||
12 | |||
13 | /** |
||
14 | * @var int |
||
15 | */ |
||
16 | protected $page; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $limit; |
||
22 | |||
23 | public function __construct(int $page, int $limit) |
||
24 | { |
||
25 | if ($page < self::MIN_PAGE_NUMBER) { |
||
26 | throw new InvalidArgumentException(sprintf("Invalid page number (%s).", $page)); |
||
27 | } |
||
28 | |||
29 | if ($limit < self::MIN_PAGE_LIMIT) { |
||
30 | throw new InvalidArgumentException(sprintf("Invalid page limit (%s).", $limit)); |
||
31 | } |
||
32 | |||
33 | $this->page = $page; |
||
34 | $this->limit = $limit; |
||
35 | } |
||
36 | |||
37 | public function page(): int |
||
38 | { |
||
39 | return $this->page; |
||
40 | } |
||
41 | |||
42 | public function limit(): int |
||
45 | } |
||
46 | |||
47 | public function withMaxLimit(int $max): self |
||
52 |