Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
13 / 13
CRAP
100.00% covered (success)
100.00%
1 / 1
PaginatorOptions
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
13 / 13
15
100.00% covered (success)
100.00%
1 / 1
 getPage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPage
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOrder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOrder
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOrderDir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOrderDir
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 getCriteria
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCriteria
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMaxPages
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMaxPages
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLimit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLimit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 searchCriteria
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Helper\Paginator;
6
7use UnexpectedValueException;
8use function in_array;
9
10class PaginatorOptions
11{
12    private int $page = 0;
13
14    private int $maxPages = 0;
15
16    private int $limit = 10;
17
18    private string $order = 'id';
19
20    private string $orderDir = 'ASC';
21
22    /**
23     * @var array<string>
24     */
25    private array $criteria = [];
26
27    public function getPage(): int
28    {
29        return $this->page;
30    }
31
32    public function setPage(int $page): static
33    {
34        $this->page = $page;
35
36        return $this;
37    }
38
39    public function getOrder(): string
40    {
41        return $this->order;
42    }
43
44    public function setOrder(string $order): static
45    {
46        $this->order = $order;
47
48        return $this;
49    }
50
51    public function getOrderDir(): string
52    {
53        return $this->orderDir;
54    }
55
56    public function setOrderDir(string $orderDir): static
57    {
58        $dirs = ['ASC', 'DESC'];
59        $dir = strtoupper($orderDir);
60
61        if (false === in_array($dir, $dirs, true)) {
62            throw new UnexpectedValueException(sprintf('Order dir must be %s', implode(', ', $dirs)));
63        }
64
65        $this->orderDir = $orderDir;
66
67        return $this;
68    }
69
70    /**
71     * @return array<string>
72     */
73    public function getCriteria(): array
74    {
75        return $this->criteria;
76    }
77
78    /**
79     * @param array<string> $criteria
80     */
81    public function setCriteria(array $criteria): static
82    {
83        $this->criteria = $criteria;
84
85        return $this;
86    }
87
88    public function getMaxPages(): int
89    {
90        return $this->maxPages;
91    }
92
93    public function setMaxPages(int $maxPages): static
94    {
95        $this->maxPages = $maxPages;
96
97        return $this;
98    }
99
100    public function getLimit(): int
101    {
102        return $this->limit;
103    }
104
105    public function setLimit(int $limit): static
106    {
107        $this->limit = $limit;
108
109        return $this;
110    }
111
112    public function searchCriteria(string $name): string
113    {
114        return array_key_exists($name, $this->criteria) ? $this->criteria[$name]
115            : '';
116    }
117}