diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b81381..9506c84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,8 @@ - Chg #163: Rename `FilterableDataInterface::withFilterHandlers()` to `FilterableDataInterface::withAddedFilterHandlers()` (@samdark) - Enh #190: Use `str_contains` for case-sensitive match in `LikeHandler` (@samdark) - Enh #194: Improve psalm annotations in `LimitableDataInterface` (@vjik) -- Bug #195: Fix invalid count in `IterableDataReader` when limit or/and offset used (@vjik) +- Bug #195: Fix invalid count in `IterableDataReader` when limit or/and offset used (@vjik) +- Enh #207: More secific Psalm type for OffsetPaginator::withCurrentPage() (@samdark) ## 1.0.1 January 25, 2023 diff --git a/src/Paginator/OffsetPaginator.php b/src/Paginator/OffsetPaginator.php index 90ffb2c..c97e7a8 100644 --- a/src/Paginator/OffsetPaginator.php +++ b/src/Paginator/OffsetPaginator.php @@ -94,6 +94,7 @@ public function __construct(ReadableDataInterface $dataReader) public function withToken(?PageToken $token): static { + /** @psalm-suppress ArgumentTypeCoercion */ return $this->withCurrentPage($token === null ? 1 : (int)$token->value); } @@ -112,6 +113,7 @@ public function withPageSize(int $pageSize): static * Get a new instance with the given current page number set. * * @param int $page Page number. + * @psalm-param positive-int $page * * @throws PaginatorException If the current page is incorrect. * @@ -119,6 +121,7 @@ public function withPageSize(int $pageSize): static */ public function withCurrentPage(int $page): self { + /** @psalm-suppress DocblockTypeContradiction */ if ($page < 1) { throw new PaginatorException('Current page should be at least 1.'); } @@ -152,9 +155,11 @@ public function getPageSize(): int * Get the current page number. * * @return int Current page number. + * @psalm-return positive-int */ public function getCurrentPage(): int { + /** @var positive-int */ return (int) $this->token->value; } @@ -314,7 +319,7 @@ public function isPaginationRequired(): bool } /** - * @psalm-return non-negative-int + * @psalm-return positive-int */ private function getInternalTotalPages(): int {