diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aa2edf..cb870a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ `OffsetableDataInterface::getOffset()` (@samdark) - Chg #187: `LimitableDataInterface::withLimit()` now accepts `null` to indicate "no limit". `0` is now a valid limit value meaning `return nothing` (@samdark) -- Chg #163: Rename `FilterableDataInterface::withFilterHandlers()` to `FilterableDataInterface::withAddedFilterHandlers()` (@samdark) +- Chg #163, #241: Remove `FilterableDataInterface::withFilterHandlers()` (@samdark, @vjik) - 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) @@ -64,6 +64,7 @@ - Chg #233: Remove nullable types from `withFilter()` and `getFilter()` methods of `FilterableDataInterface` (@vjik) - Bug #234: Fix handling of `null` values in `IterableDataReader` (@vjik) - New #236: Add `PaginatorInterface::getFilter()` method (@vjik) +- Chg #241: Remove `FilterHandlerInterface` interface (@vjik) ## 1.0.1 January 25, 2023 diff --git a/src/Reader/FilterHandlerInterface.php b/src/Reader/FilterHandlerInterface.php deleted file mode 100644 index 4238525..0000000 --- a/src/Reader/FilterHandlerInterface.php +++ /dev/null @@ -1,22 +0,0 @@ -filter = new All(); } - /** - * @psalm-return $this - */ - public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandlers): static + public function withAddedFilterHandlers(IterableFilterHandlerInterface ...$filterHandlers): self { $new = clone $this; $new->context = new Context( @@ -294,7 +288,7 @@ static function (array|object $itemA, array|object $itemB) use ($criteria) { } /** - * @param FilterHandlerInterface[] $filterHandlers + * @param IterableFilterHandlerInterface[] $filterHandlers * * @return IterableFilterHandlerInterface[] * @psalm-return array @@ -302,20 +296,9 @@ static function (array|object $itemA, array|object $itemB) use ($criteria) { private function prepareFilterHandlers(array $filterHandlers): array { $result = []; - foreach ($filterHandlers as $filterHandler) { - if (!$filterHandler instanceof IterableFilterHandlerInterface) { - throw new DataReaderException( - sprintf( - '%s::withFilterHandlers() accepts instances of %s only.', - self::class, - IterableFilterHandlerInterface::class, - ), - ); - } $result[$filterHandler->getFilterClass()] = $filterHandler; } - return $result; } diff --git a/src/Reader/Iterable/IterableFilterHandlerInterface.php b/src/Reader/Iterable/IterableFilterHandlerInterface.php index 0e9348d..f28ee10 100644 --- a/src/Reader/Iterable/IterableFilterHandlerInterface.php +++ b/src/Reader/Iterable/IterableFilterHandlerInterface.php @@ -4,14 +4,13 @@ namespace Yiisoft\Data\Reader\Iterable; -use Yiisoft\Data\Reader\FilterHandlerInterface; use Yiisoft\Data\Reader\FilterInterface; /** * Iterable filter handler checks whether an item matches criteria defined * in the filter with the same operator. */ -interface IterableFilterHandlerInterface extends FilterHandlerInterface +interface IterableFilterHandlerInterface { /** * Check whether an item matches iterable filter handlers @@ -23,4 +22,15 @@ interface IterableFilterHandlerInterface extends FilterHandlerInterface * @return bool Whether item matches the filter. */ public function match(array|object $item, FilterInterface $filter, Context $context): bool; + + /** + * Get matching filter class name. + * + * If the filter is active, a corresponding handler will be used during matching. + * + * @return string The filter class name. + * + * @psalm-return class-string + */ + public function getFilterClass(): string; } diff --git a/tests/Paginator/KeysetPaginatorTest.php b/tests/Paginator/KeysetPaginatorTest.php index 0d522bf..34873b5 100644 --- a/tests/Paginator/KeysetPaginatorTest.php +++ b/tests/Paginator/KeysetPaginatorTest.php @@ -20,7 +20,6 @@ use Yiisoft\Data\Reader\Filter\LessThan; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\FilterableDataInterface; -use Yiisoft\Data\Reader\FilterHandlerInterface; use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Reader\LimitableDataInterface; @@ -126,11 +125,6 @@ public function withFilter(?FilterInterface $filter): static return clone $this; } - public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandlers): static - { - return clone $this; - } - public function getFilter(): FilterInterface { return new All(); @@ -1175,11 +1169,6 @@ public function withFilter(?FilterInterface $filter): static return clone $this; } - public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandlers): static - { - return clone $this; - } - public function getFilter(): FilterInterface { return new All(); diff --git a/tests/Reader/Iterable/IterableDataReaderTest.php b/tests/Reader/Iterable/IterableDataReaderTest.php index c0a3a45..515593a 100644 --- a/tests/Reader/Iterable/IterableDataReaderTest.php +++ b/tests/Reader/Iterable/IterableDataReaderTest.php @@ -8,7 +8,6 @@ use Generator; use InvalidArgumentException; use LogicException; -use Yiisoft\Data\Reader\DataReaderException; use Yiisoft\Data\Reader\Filter\All; use Yiisoft\Data\Reader\Filter\AndX; use Yiisoft\Data\Reader\Filter\OrX; @@ -20,7 +19,6 @@ use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Filter\Like; use Yiisoft\Data\Reader\Filter\Not; -use Yiisoft\Data\Reader\FilterHandlerInterface; use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\Context; use Yiisoft\Data\Reader\Iterable\IterableDataReader; @@ -76,26 +74,6 @@ public function testImmutability(): void $this->assertNotSame($reader, $reader->withLimit(1)); } - public function testExceptionOnPassingNonIterableFilters(): void - { - $nonIterableFilterHandler = new class implements FilterHandlerInterface { - public function getFilterClass(): string - { - return '?'; - } - }; - - $this->expectException(DataReaderException::class); - $message = sprintf( - '%s::withFilterHandlers() accepts instances of %s only.', - IterableDataReader::class, - IterableFilterHandlerInterface::class, - ); - $this->expectExceptionMessage($message); - - (new IterableDataReader([]))->withAddedFilterHandlers($nonIterableFilterHandler); - } - public function testWithLimitFailForNegativeValues(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Support/MutationDataReader.php b/tests/Support/MutationDataReader.php index e8ef7da..85567e2 100644 --- a/tests/Support/MutationDataReader.php +++ b/tests/Support/MutationDataReader.php @@ -6,7 +6,6 @@ use Closure; use Yiisoft\Data\Reader\FilterableDataInterface; -use Yiisoft\Data\Reader\FilterHandlerInterface; use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Reader\LimitableDataInterface; @@ -32,13 +31,6 @@ public function withFilter(FilterInterface $filter): static return $new; } - public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandlers): static - { - $new = clone $this; - $new->decorated = $this->decorated->withAddedFilterHandlers(...$filterHandlers); - return $new; - } - public function withLimit(?int $limit): static { $new = clone $this;