Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve psalm annotations in LimitableDataInterface #194

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
value meaning `return nothing` (@samdark)
- 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)

## 1.0.1 January 25, 2023
Expand Down
1 change: 1 addition & 0 deletions src/Paginator/KeysetPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class KeysetPaginator implements PaginatorInterface

/**
* @var int Maximum number of items per page.
* @psalm-var positive-int
*/
private int $pageSize = self::DEFAULT_PAGE_SIZE;
private ?PageToken $token = null;
Expand Down
1 change: 1 addition & 0 deletions src/Paginator/OffsetPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public function read(): iterable
$dataReaderLimit = $this->dataReader->getLimit();

if ($dataReaderLimit !== null && ($this->getOffset() + $this->pageSize) > $dataReaderLimit) {
/** @psalm-var non-negative-int $limit */
$limit = $dataReaderLimit - $this->getOffset();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Reader/Iterable/IterableDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ final class IterableDataReader implements DataReaderInterface
{
private ?Sort $sort = null;
private ?FilterInterface $filter = null;

/**
* @psalm-var non-negative-int|null
*/
private ?int $limit = null;
private int $offset = 0;

Expand Down
8 changes: 6 additions & 2 deletions src/Reader/LimitableDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ interface LimitableDataInterface
/**
* Get a new instance with the limit set.
*
* @param ?int $limit Limit. `null` means no limit.
* @param int|null $limit Limit. `null` means no limit.
*
* @throws InvalidArgumentException If the limit is less than zero.
*
* @return static New instance.
*
* @pslam-param non-negative-int|null $limit
* @psalm-return $this
*/
public function withLimit(?int $limit): static;

/**
* Get current limit.
*
* @return ?int Limit. `null` means no limit.
* @return int|null Limit. `null` means no limit.
*
* @psalm-return non-negative-int|null
*/
public function getLimit(): ?int;
}
Loading