Lines
100.00%
6 / 6
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| 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 | ||
| 5 | final class SearchPagination | |
| 6 | { | |
| 7 | public const int DEFAULT_RESULTS_PER_PAGE = 100; | |
| 8 | ||
| 9 | public const int MIN_RESULTS_PER_PAGE = 1; | |
| 10 | ||
| 11 | public const int 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 | } |