Skip to content

Commit

Permalink
Fix #207: More secific Psalm type for OffsetPaginator::withCurrentPage()
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark authored Oct 18, 2024
1 parent 2ad813e commit 1422143
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion src/Paginator/OffsetPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -112,13 +113,15 @@ 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.
*
* @return self New instance.
*/
public function withCurrentPage(int $page): self
{
/** @psalm-suppress DocblockTypeContradiction */
if ($page < 1) {
throw new PaginatorException('Current page should be at least 1.');
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -314,7 +319,7 @@ public function isPaginationRequired(): bool
}

/**
* @psalm-return non-negative-int
* @psalm-return positive-int
*/
private function getInternalTotalPages(): int
{
Expand Down

0 comments on commit 1422143

Please sign in to comment.