Pagination::getSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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