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 committed Oct 17, 2024
1 parent 2ad813e commit 2b5f274
Showing 1 changed file with 6 additions and 1 deletion.
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 2b5f274

Please sign in to comment.