Test Failed
Push — master ( 286c96...e21ea4 )
by Laurens
01:29
created

Pagination::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\eCurring\Resource\Curser;
6
7
use LauLamanApps\eCurring\Resource\Exception\NonExistentPageNumberException;
8
9
final class Pagination
10
{
11
    /**
12
     * @var int
13
     */
14
    private $size;
15
16
    /**
17
     * @var int
18
     */
19
    private $number;
20
21
    /**
22
     * @throws NonExistentPageNumberException
23
     */
24
    public function __construct(int $size, ?int $page = 1)
25
    {
26
        if ($page < 1) {
27
            throw new NonExistentPageNumberException('Page number can not be lower than 1');
28
        }
29
30
        $this->size = $size;
31
        $this->number = $page;
32
    }
33
34
    public function getSize(): int
35
    {
36
        return $this->size;
37
    }
38
39
    public function getNumber(): int
40
    {
41
        return $this->number;
42
    }
43
44
    public function getQueryOptions(): array
45
    {
46
        return [
47
            'page' => [
48
                'number' => $this->number,
49
                'size' => $this->size,
50
            ]
51
        ];
52
    }
53
}
54