diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a3b4e..ce7ab9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Paginator/KeysetPaginator.php b/src/Paginator/KeysetPaginator.php index cb780aa..6945ee5 100644 --- a/src/Paginator/KeysetPaginator.php +++ b/src/Paginator/KeysetPaginator.php @@ -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; diff --git a/src/Paginator/OffsetPaginator.php b/src/Paginator/OffsetPaginator.php index c2a6973..da719c6 100644 --- a/src/Paginator/OffsetPaginator.php +++ b/src/Paginator/OffsetPaginator.php @@ -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(); } diff --git a/src/Reader/Iterable/IterableDataReader.php b/src/Reader/Iterable/IterableDataReader.php index e5e49a6..0a3911f 100644 --- a/src/Reader/Iterable/IterableDataReader.php +++ b/src/Reader/Iterable/IterableDataReader.php @@ -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; diff --git a/src/Reader/LimitableDataInterface.php b/src/Reader/LimitableDataInterface.php index c2823a2..6230d95 100644 --- a/src/Reader/LimitableDataInterface.php +++ b/src/Reader/LimitableDataInterface.php @@ -14,11 +14,13 @@ 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; @@ -26,7 +28,9 @@ 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; }