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

Pagination   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getQueryOptions() 0 6 1
A getSize() 0 3 1
A getNumber() 0 3 1
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