From 154f82a1a60c433544fe551717c50c42da46a799 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 15 Nov 2023 21:25:23 +0300 Subject: [PATCH 01/15] `LimitableDataInterface` --- psalm-php80.xml | 2 ++ psalm.xml | 2 ++ src/Paginator/KeysetPaginator.php | 14 ++++++++--- src/Paginator/OffsetPaginator.php | 12 +++++++-- src/Paginator/PaginatorInterface.php | 5 +++- src/Reader/DataReaderInterface.php | 2 ++ src/Reader/LimitableDataInterface.php | 35 +++++++++++++++++++++++++++ src/Reader/ReadableDataInterface.php | 22 ----------------- 8 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 src/Reader/LimitableDataInterface.php diff --git a/psalm-php80.xml b/psalm-php80.xml index f3ed238f..ba4ad097 100644 --- a/psalm-php80.xml +++ b/psalm-php80.xml @@ -1,6 +1,8 @@ &FilterableDataInterface&SortableDataInterface + * @psalm-var ReadableDataInterface&LimitableDataInterface&FilterableDataInterface&SortableDataInterface */ private ReadableDataInterface $dataReader; @@ -82,11 +83,18 @@ final class KeysetPaginator implements PaginatorInterface /** * @param ReadableDataInterface $dataReader Data reader being paginated. - * @psalm-param ReadableDataInterface&FilterableDataInterface&SortableDataInterface $dataReader + * @psalm-param ReadableDataInterface&LimitableDataInterface&FilterableDataInterface&SortableDataInterface $dataReader * @psalm-suppress DocblockTypeContradiction Needed to allow validating `$dataReader` */ public function __construct(ReadableDataInterface $dataReader) { + if (!$dataReader instanceof LimitableDataInterface) { + throw new InvalidArgumentException(sprintf( + 'Data reader should implement "%s" to be used with keyset paginator.', + LimitableDataInterface::class, + )); + } + if (!$dataReader instanceof FilterableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" to be used with keyset paginator.', @@ -289,7 +297,7 @@ private function reverseData(array $data): array } /** - * @psalm-param ReadableDataInterface&FilterableDataInterface&SortableDataInterface $dataReader + * @psalm-param ReadableDataInterface&LimitableDataInterface&FilterableDataInterface&SortableDataInterface $dataReader */ private function previousPageExist(ReadableDataInterface $dataReader, Sort $sort): bool { diff --git a/src/Paginator/OffsetPaginator.php b/src/Paginator/OffsetPaginator.php index 0dd5c132..62d32402 100644 --- a/src/Paginator/OffsetPaginator.php +++ b/src/Paginator/OffsetPaginator.php @@ -7,6 +7,7 @@ use Generator; use InvalidArgumentException; use Yiisoft\Data\Reader\CountableDataInterface; +use Yiisoft\Data\Reader\LimitableDataInterface; use Yiisoft\Data\Reader\OffsetableDataInterface; use Yiisoft\Data\Reader\ReadableDataInterface; use Yiisoft\Data\Reader\Sort; @@ -50,17 +51,24 @@ final class OffsetPaginator implements PaginatorInterface /** * Data reader being paginated. * - * @psalm-var ReadableDataInterface&OffsetableDataInterface&CountableDataInterface + * @psalm-var ReadableDataInterface&LimitableDataInterface&OffsetableDataInterface&CountableDataInterface */ private ReadableDataInterface $dataReader; /** * @param ReadableDataInterface $dataReader Data reader being paginated. - * @psalm-param ReadableDataInterface&OffsetableDataInterface&CountableDataInterface $dataReader + * @psalm-param ReadableDataInterface&LimitableDataInterface&OffsetableDataInterface&CountableDataInterface $dataReader * @psalm-suppress DocblockTypeContradiction Needed to allow validating `$dataReader` */ public function __construct(ReadableDataInterface $dataReader) { + if (!$dataReader instanceof LimitableDataInterface) { + throw new InvalidArgumentException(sprintf( + 'Data reader should implement "%s" in order to be used with offset paginator.', + LimitableDataInterface::class, + )); + } + if (!$dataReader instanceof OffsetableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" in order to be used with offset paginator.', diff --git a/src/Paginator/PaginatorInterface.php b/src/Paginator/PaginatorInterface.php index 58a69e2e..a0ea3bed 100644 --- a/src/Paginator/PaginatorInterface.php +++ b/src/Paginator/PaginatorInterface.php @@ -4,6 +4,7 @@ namespace Yiisoft\Data\Paginator; +use Yiisoft\Data\Reader\ReadableDataInterface; use Yiisoft\Data\Reader\Sort; /** @@ -14,8 +15,10 @@ * * @template TKey as array-key * @template TValue as array|object + * + * @extends ReadableDataInterface */ -interface PaginatorInterface +interface PaginatorInterface extends ReadableDataInterface { /** * Page size that is used in case it is not set explicitly. diff --git a/src/Reader/DataReaderInterface.php b/src/Reader/DataReaderInterface.php index b1ca8c78..dda76e4f 100644 --- a/src/Reader/DataReaderInterface.php +++ b/src/Reader/DataReaderInterface.php @@ -20,10 +20,12 @@ * @template TValue as array|object * * @extends ReadableDataInterface + * @extends LimitableDataInterface * @extends IteratorAggregate */ interface DataReaderInterface extends ReadableDataInterface, + LimitableDataInterface, OffsetableDataInterface, CountableDataInterface, SortableDataInterface, diff --git a/src/Reader/LimitableDataInterface.php b/src/Reader/LimitableDataInterface.php new file mode 100644 index 00000000..566028ca --- /dev/null +++ b/src/Reader/LimitableDataInterface.php @@ -0,0 +1,35 @@ + */ public function read(): iterable; - - /** - * Get a next item from the data set. - * - * @return array|object|null An item or null if there is none. - * @psalm-return TValue|null - */ - public function readOne(): array|object|null; } From 5c487867498cbcc5b95b3fc789de645044989058 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 15 Nov 2023 18:25:47 +0000 Subject: [PATCH 02/15] Apply fixes from StyleCI --- src/Reader/LimitableDataInterface.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Reader/LimitableDataInterface.php b/src/Reader/LimitableDataInterface.php index 566028ca..8236c934 100644 --- a/src/Reader/LimitableDataInterface.php +++ b/src/Reader/LimitableDataInterface.php @@ -12,7 +12,6 @@ */ interface LimitableDataInterface { - /** * Get a new instance with limit set. * From 1336ae8e120af47647b20c421a8baf696b7dcde9 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 10:40:38 +0300 Subject: [PATCH 03/15] fix --- src/Paginator/KeysetPaginator.php | 21 +++++++++++++++------ src/Paginator/OffsetPaginator.php | 20 ++++++++++++++------ src/Reader/DataReaderInterface.php | 1 - src/Reader/LimitableDataInterface.php | 12 ------------ src/Reader/ReadableDataInterface.php | 8 ++++++++ 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/Paginator/KeysetPaginator.php b/src/Paginator/KeysetPaginator.php index a22c880f..44239e4a 100644 --- a/src/Paginator/KeysetPaginator.php +++ b/src/Paginator/KeysetPaginator.php @@ -88,24 +88,24 @@ final class KeysetPaginator implements PaginatorInterface */ public function __construct(ReadableDataInterface $dataReader) { - if (!$dataReader instanceof LimitableDataInterface) { + if (!$dataReader instanceof FilterableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" to be used with keyset paginator.', - LimitableDataInterface::class, + FilterableDataInterface::class, )); } - if (!$dataReader instanceof FilterableDataInterface) { + if (!$dataReader instanceof SortableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" to be used with keyset paginator.', - FilterableDataInterface::class, + SortableDataInterface::class, )); } - if (!$dataReader instanceof SortableDataInterface) { + if (!$dataReader instanceof LimitableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" to be used with keyset paginator.', - SortableDataInterface::class, + LimitableDataInterface::class, )); } @@ -193,6 +193,15 @@ public function read(): iterable return $this->readCache = $data; } + public function readOne(): array|object|null + { + foreach ($this->read() as $item) { + return $item; + } + + return null; + } + public function getPageSize(): int { return $this->pageSize; diff --git a/src/Paginator/OffsetPaginator.php b/src/Paginator/OffsetPaginator.php index 62d32402..823a7c2d 100644 --- a/src/Paginator/OffsetPaginator.php +++ b/src/Paginator/OffsetPaginator.php @@ -62,24 +62,24 @@ final class OffsetPaginator implements PaginatorInterface */ public function __construct(ReadableDataInterface $dataReader) { - if (!$dataReader instanceof LimitableDataInterface) { + if (!$dataReader instanceof OffsetableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" in order to be used with offset paginator.', - LimitableDataInterface::class, + OffsetableDataInterface::class, )); } - if (!$dataReader instanceof OffsetableDataInterface) { + if (!$dataReader instanceof CountableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" in order to be used with offset paginator.', - OffsetableDataInterface::class, + CountableDataInterface::class, )); } - if (!$dataReader instanceof CountableDataInterface) { + if (!$dataReader instanceof LimitableDataInterface) { throw new InvalidArgumentException(sprintf( 'Data reader should implement "%s" in order to be used with offset paginator.', - CountableDataInterface::class, + LimitableDataInterface::class, )); } @@ -221,6 +221,14 @@ public function read(): iterable ->read(); } + public function readOne(): array|object|null + { + return $this->dataReader + ->withLimit(1) + ->withOffset($this->getOffset()) + ->readOne(); + } + public function isOnFirstPage(): bool { return $this->currentPage === 1; diff --git a/src/Reader/DataReaderInterface.php b/src/Reader/DataReaderInterface.php index dda76e4f..e266da5f 100644 --- a/src/Reader/DataReaderInterface.php +++ b/src/Reader/DataReaderInterface.php @@ -20,7 +20,6 @@ * @template TValue as array|object * * @extends ReadableDataInterface - * @extends LimitableDataInterface * @extends IteratorAggregate */ interface DataReaderInterface extends diff --git a/src/Reader/LimitableDataInterface.php b/src/Reader/LimitableDataInterface.php index 8236c934..0bbe2f03 100644 --- a/src/Reader/LimitableDataInterface.php +++ b/src/Reader/LimitableDataInterface.php @@ -6,10 +6,6 @@ use InvalidArgumentException; -/** - * @template TKey as array-key - * @template TValue as array|object - */ interface LimitableDataInterface { /** @@ -23,12 +19,4 @@ interface LimitableDataInterface * @psalm-return $this */ public function withLimit(int $limit): static; - - /** - * Get a next item from the data set. - * - * @return array|object|null An item or null if there is none. - * @psalm-return TValue|null - */ - public function readOne(): array|object|null; } diff --git a/src/Reader/ReadableDataInterface.php b/src/Reader/ReadableDataInterface.php index 6a36cbe2..29bb4f99 100644 --- a/src/Reader/ReadableDataInterface.php +++ b/src/Reader/ReadableDataInterface.php @@ -20,4 +20,12 @@ interface ReadableDataInterface * @psalm-return iterable */ public function read(): iterable; + + /** + * Get a next item from the data set. + * + * @return array|object|null An item or null if there is none. + * @psalm-return TValue|null + */ + public function readOne(): array|object|null; } From 3e4441e5fb3917109305a661f6f2dd92964b53c2 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 11:10:20 +0300 Subject: [PATCH 04/15] changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beb5f8a3..2ac2ec28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Yii Data Change Log -## 1.0.2 under development +## 2.0.0 under development -- no changes in this release. +- New #150: Extract `withLimit()` from `ReadableDataInterface` to `LimitableDataInterface` (@vjik) +- Enh #150: `PaginatorInterface` is extend `ReadableDataInterface` (@vjik) ## 1.0.1 January 25, 2023 From 514f0a4f0d2662baa193bc8684e881f05d17ff9e Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 11:15:49 +0300 Subject: [PATCH 05/15] add test --- tests/Paginator/KeysetPaginatorTest.php | 51 ++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/Paginator/KeysetPaginatorTest.php b/tests/Paginator/KeysetPaginatorTest.php index e86a139f..eb53706b 100644 --- a/tests/Paginator/KeysetPaginatorTest.php +++ b/tests/Paginator/KeysetPaginatorTest.php @@ -17,6 +17,7 @@ use Yiisoft\Data\Reader\FilterHandlerInterface; use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableDataReader; +use Yiisoft\Data\Reader\LimitableDataInterface; use Yiisoft\Data\Reader\ReadableDataInterface; use Yiisoft\Data\Reader\Sort; use Yiisoft\Data\Reader\SortableDataInterface; @@ -79,6 +80,17 @@ public function testDataReaderWithoutSortableInterface(): void new KeysetPaginator($this->getNonSortableDataReader()); } + public function testDataReaderWithoutLimitableInterface(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf( + 'Data reader should implement "%s" to be used with keyset paginator.', + LimitableDataInterface::class, + )); + + new KeysetPaginator($this->getNonLimitableDataReader()); + } + public function testThrowsExceptionWhenReaderHasNoSort(): void { $dataReader = new IterableDataReader($this->getDataSet()); @@ -509,9 +521,44 @@ private function getDataSet(array $keys = null): array return $result; } + private function getNonLimitableDataReader() + { + return new class () implements ReadableDataInterface, SortableDataInterface, FilterableDataInterface { + public function withSort(?Sort $sort): static + { + return clone $this; + } + + public function getSort(): ?Sort + { + return Sort::only([]); + } + + public function read(): iterable + { + return []; + } + + public function readOne(): array|object|null + { + return null; + } + + public function withFilter(FilterInterface $filter): static + { + return clone $this; + } + + public function withFilterHandlers(FilterHandlerInterface ...$filterHandlers): static + { + return clone $this; + } + }; + } + private function getNonSortableDataReader() { - return new class () implements ReadableDataInterface, FilterableDataInterface { + return new class () implements ReadableDataInterface, LimitableDataInterface, FilterableDataInterface { public function withLimit(int $limit): static { return clone $this; @@ -541,7 +588,7 @@ public function withFilterHandlers(FilterHandlerInterface ...$filterHandlers): s private function getNonFilterableDataReader() { - return new class () implements ReadableDataInterface, SortableDataInterface { + return new class () implements ReadableDataInterface, LimitableDataInterface, SortableDataInterface { public function withLimit(int $limit): static { return clone $this; From e005239c0cd71ebbd8ee4449a4030cc22b8b718e Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 11:30:17 +0300 Subject: [PATCH 06/15] improve --- src/Reader/LimitableDataInterface.php | 3 + tests/Paginator/KeysetPaginatorTest.php | 103 +++++++++++++++--------- tests/Paginator/OffsetPaginatorTest.php | 71 ++++++++++++++++ 3 files changed, 141 insertions(+), 36 deletions(-) diff --git a/src/Reader/LimitableDataInterface.php b/src/Reader/LimitableDataInterface.php index 0bbe2f03..c9fdd243 100644 --- a/src/Reader/LimitableDataInterface.php +++ b/src/Reader/LimitableDataInterface.php @@ -6,6 +6,9 @@ use InvalidArgumentException; +/** + * Data that could be limited. + */ interface LimitableDataInterface { /** diff --git a/tests/Paginator/KeysetPaginatorTest.php b/tests/Paginator/KeysetPaginatorTest.php index eb53706b..70c3b241 100644 --- a/tests/Paginator/KeysetPaginatorTest.php +++ b/tests/Paginator/KeysetPaginatorTest.php @@ -82,13 +82,45 @@ public function testDataReaderWithoutSortableInterface(): void public function testDataReaderWithoutLimitableInterface(): void { + $dataReader = new class () implements ReadableDataInterface, SortableDataInterface, FilterableDataInterface { + public function withSort(?Sort $sort): static + { + return clone $this; + } + + public function getSort(): ?Sort + { + return Sort::only([]); + } + + public function read(): iterable + { + return []; + } + + public function readOne(): array|object|null + { + return null; + } + + public function withFilter(FilterInterface $filter): static + { + return clone $this; + } + + public function withFilterHandlers(FilterHandlerInterface ...$filterHandlers): static + { + return clone $this; + } + }; + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(sprintf( 'Data reader should implement "%s" to be used with keyset paginator.', LimitableDataInterface::class, )); - new KeysetPaginator($this->getNonLimitableDataReader()); + new KeysetPaginator($dataReader); } public function testThrowsExceptionWhenReaderHasNoSort(): void @@ -268,6 +300,40 @@ public function testReadSecondPageOrderedByName(): void $this->assertSame((string)$last['name'], $paginator->getNextPageToken()); } + public function dataReadOne(): array + { + $data = []; + + $data['empty'] = [ + null, + new KeysetPaginator( + (new IterableDataReader([]))->withSort(Sort::only(['id'])->withOrderString('id')) + ), + ]; + + $data['base'] = [ + ['id' => 2, 'name' => 'John'], + new KeysetPaginator( + (new IterableDataReader([ + ['id' => 1, 'name' => 'Mike'], + ['id' => 2, 'name' => 'John'], + ])) + ->withSort(Sort::only(['id'])->withOrderString('-id')) + ), + ]; + + return $data; + } + + /** + * @dataProvider dataReadOne + */ + public function testReadOne(mixed $expected, KeysetPaginator $paginator): void + { + $result = $paginator->readOne(); + $this->assertSame($expected, $result); + } + public function testBackwardPagination(): void { $sort = Sort::only(['id', 'name'])->withOrderString('id'); @@ -521,41 +587,6 @@ private function getDataSet(array $keys = null): array return $result; } - private function getNonLimitableDataReader() - { - return new class () implements ReadableDataInterface, SortableDataInterface, FilterableDataInterface { - public function withSort(?Sort $sort): static - { - return clone $this; - } - - public function getSort(): ?Sort - { - return Sort::only([]); - } - - public function read(): iterable - { - return []; - } - - public function readOne(): array|object|null - { - return null; - } - - public function withFilter(FilterInterface $filter): static - { - return clone $this; - } - - public function withFilterHandlers(FilterHandlerInterface ...$filterHandlers): static - { - return clone $this; - } - }; - } - private function getNonSortableDataReader() { return new class () implements ReadableDataInterface, LimitableDataInterface, FilterableDataInterface { diff --git a/tests/Paginator/OffsetPaginatorTest.php b/tests/Paginator/OffsetPaginatorTest.php index bc993b75..5988c0b8 100644 --- a/tests/Paginator/OffsetPaginatorTest.php +++ b/tests/Paginator/OffsetPaginatorTest.php @@ -10,6 +10,7 @@ use Yiisoft\Data\Paginator\PaginatorInterface; use Yiisoft\Data\Reader\CountableDataInterface; use Yiisoft\Data\Reader\Iterable\IterableDataReader; +use Yiisoft\Data\Reader\LimitableDataInterface; use Yiisoft\Data\Reader\OffsetableDataInterface; use Yiisoft\Data\Reader\ReadableDataInterface; use Yiisoft\Data\Reader\Sort; @@ -119,6 +120,45 @@ public function withOffset(int $offset): static new OffsetPaginator($nonCountableDataReader); } + public function testDataReaderWithoutLimitableInterface(): void + { + $nonLimitableDataReader = new class () implements + ReadableDataInterface, + CountableDataInterface, + OffsetableDataInterface { + public function read(): iterable + { + return []; + } + + public function readOne(): array|object|null + { + return null; + } + + public function count(): int + { + return 0; + } + + public function withOffset(int $offset): static + { + // do nothing + return $this; + } + }; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + sprintf( + 'Data reader should implement "%s" in order to be used with offset paginator.', + LimitableDataInterface::class, + ) + ); + + new OffsetPaginator($nonLimitableDataReader); + } + public function testDefaultState(): void { $dataReader = new IterableDataReader(self::DEFAULT_DATASET); @@ -253,6 +293,37 @@ public function testReadLastPage(): void $this->assertSame($expected, array_values($this->iterableToArray($paginator->read()))); } + public function dataReadOne(): array + { + $data = []; + + $data['empty'] = [ + null, + new OffsetPaginator(new IterableDataReader([])), + ]; + + $data['base'] = [ + ['id' => 2, 'name' => 'John'], + (new OffsetPaginator( + new IterableDataReader([ + ['id' => 1, 'name' => 'Mike'], + ['id' => 2, 'name' => 'John'], + ]) + ))->withPageSize(1)->withCurrentPage(2), + ]; + + return $data; + } + + /** + * @dataProvider dataReadOne + */ + public function testReadOne(mixed $expected, OffsetPaginator $paginator): void + { + $result = $paginator->readOne(); + $this->assertSame($expected, $result); + } + public function testTotalPages(): void { $dataReader = new IterableDataReader(self::DEFAULT_DATASET); From 3979a59cc0125b1444e886e1d7fbb36ba2b1e628 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 11:32:16 +0300 Subject: [PATCH 07/15] readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9ae9da92..38eac5be 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,7 @@ Additional interfaces could be implemented in order to support different paginat - `CountableDataInterface` - allows getting total number of items in data reader. - `FilterableDataInterface` - allows returning subset of items based on criteria. +- `LimitableDataInterface` - allows returning limited subset of items. - `SortableDataInterface` - allows sorting by one or multiple fields. - `OffsetableDataInterface` - allows to skip first N items when reading data. From 44c011f1fa254b884c76661e8a7ab508cc394f28 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 13:03:44 +0300 Subject: [PATCH 08/15] Fix comment --- src/Reader/ReadableDataInterface.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Reader/ReadableDataInterface.php b/src/Reader/ReadableDataInterface.php index 29bb4f99..8f085bde 100644 --- a/src/Reader/ReadableDataInterface.php +++ b/src/Reader/ReadableDataInterface.php @@ -5,8 +5,7 @@ namespace Yiisoft\Data\Reader; /** - * Readable data is a data set that could be read up to number of items - * defined by limit either one by one or by getting an iterator. + * Readable data is a data set that could be read up by getting an iterator or reading one item from set. * * @template TKey as array-key * @template TValue as array|object From f61005dba0b9130aee3f082701d5ea745aff0beb Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 13:24:22 +0300 Subject: [PATCH 09/15] Improve bc.yml --- .github/workflows/bc.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index ba3e9ef1..15c4880a 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -1,6 +1,15 @@ on: - - pull_request - - push + pull_request: + paths: + - 'src/**' + - '.github/workflows/bc.yml' + - 'composer.json' + push: + branches: ['master'] + paths: + - 'src/**' + - '.github/workflows/bc.yml' + - 'composer.json' name: backwards compatibility From fb4ea60cc9826d58f0bcf14d14340d8552f79b7c Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 13:33:31 +0300 Subject: [PATCH 10/15] config --- infection.json.dist | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/infection.json.dist b/infection.json.dist index 3776e223..204fd163 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -11,6 +11,21 @@ } }, "mutators": { - "@default": true + "@default": true, + "LogicalAndAllSubExprNegation": { + "ignore": [ + "Yiisoft\\Data\\Paginator\\KeysetPaginator::isOnFirstPage" + ] + }, + "IncrementInteger": { + "ignore": [ + "Yiisoft\\Data\\Paginator\\OffsetPaginator::readOne" + ] + }, + "DecrementInteger": { + "ignore": [ + "Yiisoft\\Data\\Paginator\\OffsetPaginator::readOne" + ] + } } } From 5b0cbf200d248b3a6afc40876a4014fd31a2881e Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 13:36:50 +0300 Subject: [PATCH 11/15] fix --- src/Reader/ReadableDataInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Reader/ReadableDataInterface.php b/src/Reader/ReadableDataInterface.php index 8f085bde..7d1d7a0e 100644 --- a/src/Reader/ReadableDataInterface.php +++ b/src/Reader/ReadableDataInterface.php @@ -21,7 +21,7 @@ interface ReadableDataInterface public function read(): iterable; /** - * Get a next item from the data set. + * Get one item from the data set. * * @return array|object|null An item or null if there is none. * @psalm-return TValue|null From c3a1ef917545c3f5ca853643243bdb5effba675f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 16 Nov 2023 15:37:30 +0300 Subject: [PATCH 12/15] Update src/Reader/ReadableDataInterface.php Co-authored-by: Aleksei Gagarin --- src/Reader/ReadableDataInterface.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Reader/ReadableDataInterface.php b/src/Reader/ReadableDataInterface.php index 7d1d7a0e..0b4d47e0 100644 --- a/src/Reader/ReadableDataInterface.php +++ b/src/Reader/ReadableDataInterface.php @@ -21,7 +21,8 @@ interface ReadableDataInterface public function read(): iterable; /** - * Get one item from the data set. + * Get the first item from the data set. + * Note that invoking this method does not impact the data set or its pointer. * * @return array|object|null An item or null if there is none. * @psalm-return TValue|null From d835311469a4efbcfec3c296ed932a44bce020ac Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 17 Nov 2023 12:49:54 +0300 Subject: [PATCH 13/15] Update CHANGELOG.md Co-authored-by: Alexander Makarov --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ac2ec28..8e217303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2.0.0 under development - New #150: Extract `withLimit()` from `ReadableDataInterface` to `LimitableDataInterface` (@vjik) -- Enh #150: `PaginatorInterface` is extend `ReadableDataInterface` (@vjik) +- Enh #150: `PaginatorInterface` now extends `ReadableDataInterface` (@vjik) ## 1.0.1 January 25, 2023 From fc996d5082e8b2e0ea76fc2340f79e666bee7bbd Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 17 Nov 2023 12:50:04 +0300 Subject: [PATCH 14/15] Update CHANGELOG.md Co-authored-by: Alexander Makarov --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e217303..cb979180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.0 under development -- New #150: Extract `withLimit()` from `ReadableDataInterface` to `LimitableDataInterface` (@vjik) +- New #150: Extract `withLimit()` from `ReadableDataInterface` into `LimitableDataInterface` (@vjik) - Enh #150: `PaginatorInterface` now extends `ReadableDataInterface` (@vjik) ## 1.0.1 January 25, 2023 From acb18a48598266c6ad1836bd13ff333d2e04b38b Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 21 Nov 2023 11:02:52 +0300 Subject: [PATCH 15/15] fix --- src/Reader/ReadableDataInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Reader/ReadableDataInterface.php b/src/Reader/ReadableDataInterface.php index 0b4d47e0..42a4cb69 100644 --- a/src/Reader/ReadableDataInterface.php +++ b/src/Reader/ReadableDataInterface.php @@ -21,7 +21,7 @@ interface ReadableDataInterface public function read(): iterable; /** - * Get the first item from the data set. + * Get one item from the data set. Which item is returned is up to implementation. * Note that invoking this method does not impact the data set or its pointer. * * @return array|object|null An item or null if there is none.