Completed
Push — master ( cc516e...32adf9 )
by Philip
20:39
created

Pagination   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 60
rs 10
1
<?php
2
3
namespace Dontdrinkandroot\Pagination;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @author Philip Washington Sorst <[email protected]>
9
 */
10
class Pagination
11
{
12
    private int $currentPage;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
13
14
    private int $perPage;
15
16
    private int $total;
17
18
    public function __construct(int $currentPage, int $perPage, int $total)
19
    {
20
        if ($currentPage < 1) {
21
            throw new InvalidArgumentException('CurrentPage must be greater than 0');
22
        }
23
24
        if ($perPage < 1) {
25
            throw new InvalidArgumentException('PerPage mustbe greater than 0');
26
        }
27
28
        if ($total < 0) {
29
            throw new InvalidArgumentException('Total must be greater equals 0');
30
        }
31
32
        $this->perPage = $perPage;
33
        $this->currentPage = $currentPage;
34
        $this->total = $total;
35
    }
36
37
    public function getCurrentPage(): int
38
    {
39
        return $this->currentPage;
40
    }
41
42
    public function getTotal(): int
43
    {
44
        return $this->total;
45
    }
46
47
    public function getTotalPages(): int
48
    {
49
        if ($this->total == 0) {
50
            return 0;
51
        }
52
53
        return (int)(($this->total - 1) / $this->perPage + 1);
54
    }
55
56
    public function getPerPage(): int
57
    {
58
        return $this->perPage;
59
    }
60
}
61