Skip to content
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
22 changes: 0 additions & 22 deletions src/Reader/FilterHandlerInterface.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Reader/FilterableDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,4 @@ public function withFilter(FilterInterface $filter): static;
* @return FilterInterface Data reading criteria.
*/
public function getFilter(): FilterInterface;

/**
* Returns new instance with additional handlers set.
*
* @param FilterHandlerInterface ...$filterHandlers Additional filter handlers.
*
* @return static New instance.
*/
public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandlers): static;
}
21 changes: 2 additions & 19 deletions src/Reader/Iterable/IterableDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use InvalidArgumentException;
use Traversable;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Data\Reader\DataReaderException;
use Yiisoft\Data\Reader\DataReaderInterface;
use Yiisoft\Data\Reader\Filter\All;
use Yiisoft\Data\Reader\FilterHandlerInterface;
use Yiisoft\Data\Reader\FilterInterface;
use Yiisoft\Data\Reader\Iterable\FilterHandler\AllHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\AndXHandler;
Expand All @@ -34,7 +32,6 @@
use function array_merge;
use function count;
use function iterator_to_array;
use function sprintf;
use function uasort;

/**
Expand Down Expand Up @@ -97,10 +94,7 @@ public function __construct(
$this->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(
Expand Down Expand Up @@ -294,28 +288,17 @@ static function (array|object $itemA, array|object $itemB) use ($criteria) {
}

/**
* @param FilterHandlerInterface[] $filterHandlers
* @param IterableFilterHandlerInterface[] $filterHandlers
*
* @return IterableFilterHandlerInterface[]
* @psalm-return array<string, IterableFilterHandlerInterface>
*/
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;
}

Expand Down
14 changes: 12 additions & 2 deletions src/Reader/Iterable/IterableFilterHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<FilterInterface>
*/
public function getFilterClass(): string;
}
11 changes: 0 additions & 11 deletions tests/Paginator/KeysetPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 0 additions & 22 deletions tests/Reader/Iterable/IterableDataReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions tests/Support/MutationDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading