Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SearchPagination | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| normalizePage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| normalizeResultsPerPage | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| offset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsbackend\Helper; |
| 4 | |
| 5 | final class SearchPagination |
| 6 | { |
| 7 | public const DEFAULT_RESULTS_PER_PAGE = 100; |
| 8 | |
| 9 | public const MIN_RESULTS_PER_PAGE = 1; |
| 10 | |
| 11 | public const MAX_RESULTS_PER_PAGE = 1000; |
| 12 | |
| 13 | public static function normalizePage(int $requestedPage): int |
| 14 | { |
| 15 | return max(self::MIN_RESULTS_PER_PAGE, $requestedPage); |
| 16 | } |
| 17 | |
| 18 | public static function normalizeResultsPerPage(int $requestedResultsPerPage): int |
| 19 | { |
| 20 | return min( |
| 21 | self::MAX_RESULTS_PER_PAGE, |
| 22 | max(self::MIN_RESULTS_PER_PAGE, $requestedResultsPerPage) |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | public static function offset(int $page, int $resultsPerPage): int |
| 27 | { |
| 28 | return (self::normalizePage($page) - 1) * $resultsPerPage; |
| 29 | } |
| 30 | } |