From 920ea759a5a6d09446983cad6c0d302822f8182d Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 24 Sep 2024 11:51:50 +0300 Subject: [PATCH 1/3] Improve psalm annotations --- src/Paginator/KeysetPaginator.php | 1 + src/Paginator/OffsetPaginator.php | 1 + src/Reader/Iterable/IterableDataReader.php | 4 ++++ src/Reader/LimitableDataInterface.php | 6 ++++-- 4 files changed, 10 insertions(+), 2 deletions(-) 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 7a8491d..cf42ebf 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..9ab189d 100644 --- a/src/Reader/LimitableDataInterface.php +++ b/src/Reader/LimitableDataInterface.php @@ -14,7 +14,7 @@ interface LimitableDataInterface /** * Get a new instance with the limit set. * - * @param ?int $limit Limit. `null` means no limit. + * @param non-negative-int|null $limit Limit. `null` means no limit. * * @throws InvalidArgumentException If the limit is less than zero. * @@ -26,7 +26,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; } From d5ae7b51662fb78f2cbb6c5cad541c099a88c59f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 24 Sep 2024 11:56:12 +0300 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e26494..3e1d439 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) ## 1.0.1 January 25, 2023 From 9b4e82f1ceb43110714317253c53442495e2bc21 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 24 Sep 2024 11:57:34 +0300 Subject: [PATCH 3/3] fix --- src/Reader/LimitableDataInterface.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Reader/LimitableDataInterface.php b/src/Reader/LimitableDataInterface.php index 9ab189d..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 non-negative-int|null $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;