From 8094499bd8343e5a71df941b80129c6a31439e7d Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Feb 2024 11:48:36 +0300 Subject: [PATCH 1/8] Simplify `FilterInterface` and `FilterHandlerInterface` --- CHANGELOG.md | 1 + src/Reader/Filter/All.php | 4 - src/Reader/Filter/Any.php | 4 - src/Reader/Filter/Between.php | 27 +--- src/Reader/Filter/Compare.php | 27 ++-- src/Reader/Filter/Equals.php | 4 - src/Reader/Filter/EqualsEmpty.php | 15 +- src/Reader/Filter/EqualsNull.php | 15 +- src/Reader/Filter/GreaterThan.php | 4 - src/Reader/Filter/GreaterThanOrEqual.php | 4 - src/Reader/Filter/Group.php | 73 +-------- src/Reader/Filter/In.php | 30 ++-- src/Reader/Filter/LessThan.php | 4 - src/Reader/Filter/LessThanOrEqual.php | 4 - src/Reader/Filter/Like.php | 16 +- src/Reader/Filter/Not.php | 15 +- src/Reader/FilterAssert.php | 91 ------------ src/Reader/FilterHandlerInterface.php | 14 +- src/Reader/FilterInterface.php | 14 -- .../Iterable/FilterHandler/AllHandler.php | 29 +++- .../Iterable/FilterHandler/AnyHandler.php | 29 +++- .../Iterable/FilterHandler/BetweenHandler.php | 30 ++-- .../Iterable/FilterHandler/CompareHandler.php | 42 ------ .../FilterHandler/EqualsEmptyHandler.php | 21 ++- .../Iterable/FilterHandler/EqualsHandler.php | 19 ++- .../FilterHandler/EqualsNullHandler.php | 20 +-- .../FilterHandler/GreaterThanHandler.php | 19 ++- .../GreaterThanOrEqualHandler.php | 19 ++- .../Iterable/FilterHandler/GroupHandler.php | 90 ----------- .../Iterable/FilterHandler/InHandler.php | 22 ++- .../FilterHandler/LessThanHandler.php | 19 ++- .../FilterHandler/LessThanOrEqualHandler.php | 19 ++- .../Iterable/FilterHandler/LikeHandler.php | 22 ++- .../Iterable/FilterHandler/NotHandler.php | 55 ++----- src/Reader/Iterable/IterableDataReader.php | 33 +---- .../IterableFilterHandlerInterface.php | 8 +- tests/Reader/Filter/AllTest.php | 88 ----------- tests/Reader/Filter/AnyTest.php | 91 ------------ tests/Reader/Filter/BetweenTest.php | 52 ------- tests/Reader/Filter/CompareTest.php | 2 +- tests/Reader/Filter/EqualsEmptyTest.php | 18 --- tests/Reader/Filter/EqualsNullTest.php | 18 --- tests/Reader/Filter/EqualsTest.php | 38 ----- .../Reader/Filter/GreaterThanOrEqualTest.php | 38 ----- tests/Reader/Filter/GreaterThanTest.php | 38 ----- tests/Reader/Filter/InTest.php | 21 +-- tests/Reader/Filter/LessThanOrEqualTest.php | 38 ----- tests/Reader/Filter/LessThanTest.php | 38 ----- tests/Reader/Filter/LikeTest.php | 18 --- tests/Reader/Filter/NotTest.php | 19 --- tests/Reader/IterableDataReaderTest.php | 117 +++------------ tests/Reader/IterableHandler/AllTest.php | 140 +++++------------- tests/Reader/IterableHandler/AnyTest.php | 140 +++++------------- tests/Reader/IterableHandler/BetweenTest.php | 71 ++++----- .../IterableHandler/EqualsEmptyTest.php | 34 +---- .../Reader/IterableHandler/EqualsNullTest.php | 44 ++---- tests/Reader/IterableHandler/EqualsTest.php | 66 +++------ .../GreaterThanOrEqualTest.php | 55 +++---- .../IterableHandler/GreaterThanTest.php | 58 +++----- tests/Reader/IterableHandler/InTest.php | 45 ++---- .../IterableHandler/LessThanOrEqualTest.php | 59 +++----- tests/Reader/IterableHandler/LessThanTest.php | 57 +++---- tests/Reader/IterableHandler/LikeTest.php | 44 ++---- tests/Reader/IterableHandler/NotTest.php | 104 +++---------- tests/Support/CustomFilter/Digital.php | 12 +- tests/Support/CustomFilter/DigitalHandler.php | 10 +- .../CustomFilter/FilterWithoutHandler.php | 11 ++ tests/TestCase.php | 14 -- 68 files changed, 581 insertions(+), 1879 deletions(-) delete mode 100644 src/Reader/FilterAssert.php delete mode 100644 src/Reader/Iterable/FilterHandler/CompareHandler.php delete mode 100644 src/Reader/Iterable/FilterHandler/GroupHandler.php delete mode 100644 tests/Reader/Filter/AllTest.php delete mode 100644 tests/Reader/Filter/AnyTest.php delete mode 100644 tests/Reader/Filter/BetweenTest.php delete mode 100644 tests/Reader/Filter/EqualsEmptyTest.php delete mode 100644 tests/Reader/Filter/EqualsNullTest.php delete mode 100644 tests/Reader/Filter/EqualsTest.php delete mode 100644 tests/Reader/Filter/GreaterThanOrEqualTest.php delete mode 100644 tests/Reader/Filter/GreaterThanTest.php delete mode 100644 tests/Reader/Filter/LessThanOrEqualTest.php delete mode 100644 tests/Reader/Filter/LessThanTest.php delete mode 100644 tests/Reader/Filter/LikeTest.php delete mode 100644 tests/Reader/Filter/NotTest.php create mode 100644 tests/Support/CustomFilter/FilterWithoutHandler.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f1dd8b..51a02093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ not found (@vjik) - Enh #161: Add more specified psalm annotations to `CountableDataInterface::count()`, `PaginatorInterface::getCurrentPageSize()` and `OffsetPaginator::getTotalItems()` (@vjik) +- Chg #165: Simplify `FilterInterface` and `FilterHandlerInterface` (@vjik) ## 1.0.1 January 25, 2023 diff --git a/src/Reader/Filter/All.php b/src/Reader/Filter/All.php index 7566f34e..5121f108 100644 --- a/src/Reader/Filter/All.php +++ b/src/Reader/Filter/All.php @@ -21,8 +21,4 @@ */ final class All extends Group { - public static function getOperator(): string - { - return 'and'; - } } diff --git a/src/Reader/Filter/Any.php b/src/Reader/Filter/Any.php index 0e130ec5..7b931e03 100644 --- a/src/Reader/Filter/Any.php +++ b/src/Reader/Filter/Any.php @@ -21,8 +21,4 @@ */ final class Any extends Group { - public static function getOperator(): string - { - return 'or'; - } } diff --git a/src/Reader/Filter/Between.php b/src/Reader/Filter/Between.php index 8de6daa3..de305923 100644 --- a/src/Reader/Filter/Between.php +++ b/src/Reader/Filter/Between.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Filter; use DateTimeInterface; -use Yiisoft\Data\Reader\FilterAssert; use Yiisoft\Data\Reader\FilterInterface; /** @@ -14,31 +13,15 @@ */ final class Between implements FilterInterface { - private bool|DateTimeInterface|float|int|string $minValue; - - private bool|DateTimeInterface|float|int|string $maxValue; - /** * @param string $field Name of the field to compare. * @param bool|DateTimeInterface|float|int|string $minValue Minimal field value. * @param bool|DateTimeInterface|float|int|string $maxValue Maximal field value. */ - public function __construct(private string $field, mixed $minValue, mixed $maxValue) - { - FilterAssert::isScalarOrInstanceOfDateTimeInterface($minValue); - FilterAssert::isScalarOrInstanceOfDateTimeInterface($maxValue); - - $this->minValue = $minValue; - $this->maxValue = $maxValue; - } - - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->field, $this->minValue, $this->maxValue]; - } - - public static function getOperator(): string - { - return 'between'; + public function __construct( + public readonly string $field, + public readonly bool|DateTimeInterface|float|int|string $minValue, + public readonly bool|DateTimeInterface|float|int|string $maxValue + ) { } } diff --git a/src/Reader/Filter/Compare.php b/src/Reader/Filter/Compare.php index 39cd4d85..5f193a29 100644 --- a/src/Reader/Filter/Compare.php +++ b/src/Reader/Filter/Compare.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Filter; use DateTimeInterface; -use Yiisoft\Data\Reader\FilterAssert; use Yiisoft\Data\Reader\FilterInterface; /** @@ -20,29 +19,25 @@ abstract class Compare implements FilterInterface * @param string $field Name of the field to compare. * @param bool|DateTimeInterface|float|int|string $value Value to compare to. */ - public function __construct(private string $field, mixed $value) + public function __construct( + public readonly string $field, + bool|DateTimeInterface|float|int|string $value + ) { + $this->value = $value; + } + + public function getValue(): float|DateTimeInterface|bool|int|string { - $this->setValue($value); + return $this->value; } /** * @param bool|DateTimeInterface|float|int|string $value Value to compare to. */ - final public function withValue(mixed $value): static + final public function withValue(bool|DateTimeInterface|float|int|string $value): static { $new = clone $this; - $new->setValue($value); + $new->value = $value; return $new; } - - public function toCriteriaArray(): array - { - return [static::getOperator(), $this->field, $this->value]; - } - - private function setValue(mixed $value): void - { - FilterAssert::isScalarOrInstanceOfDateTimeInterface($value); - $this->value = $value; - } } diff --git a/src/Reader/Filter/Equals.php b/src/Reader/Filter/Equals.php index d49bc483..6b7ef70e 100644 --- a/src/Reader/Filter/Equals.php +++ b/src/Reader/Filter/Equals.php @@ -9,8 +9,4 @@ */ final class Equals extends Compare { - public static function getOperator(): string - { - return '='; - } } diff --git a/src/Reader/Filter/EqualsEmpty.php b/src/Reader/Filter/EqualsEmpty.php index 5ed330ff..0bc1981f 100644 --- a/src/Reader/Filter/EqualsEmpty.php +++ b/src/Reader/Filter/EqualsEmpty.php @@ -14,17 +14,8 @@ final class EqualsEmpty implements FilterInterface /** * @param string $field Name of the field to check. */ - public function __construct(private string $field) - { - } - - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->field]; - } - - public static function getOperator(): string - { - return 'empty'; + public function __construct( + public readonly string $field + ) { } } diff --git a/src/Reader/Filter/EqualsNull.php b/src/Reader/Filter/EqualsNull.php index 164d8c15..d3d354e4 100644 --- a/src/Reader/Filter/EqualsNull.php +++ b/src/Reader/Filter/EqualsNull.php @@ -14,17 +14,8 @@ final class EqualsNull implements FilterInterface /** * @param string $field Name of the field to check. */ - public function __construct(private string $field) - { - } - - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->field]; - } - - public static function getOperator(): string - { - return 'null'; + public function __construct( + public readonly string $field + ) { } } diff --git a/src/Reader/Filter/GreaterThan.php b/src/Reader/Filter/GreaterThan.php index 62995ae8..5ac460e0 100644 --- a/src/Reader/Filter/GreaterThan.php +++ b/src/Reader/Filter/GreaterThan.php @@ -10,8 +10,4 @@ */ final class GreaterThan extends Compare { - public static function getOperator(): string - { - return '>'; - } } diff --git a/src/Reader/Filter/GreaterThanOrEqual.php b/src/Reader/Filter/GreaterThanOrEqual.php index 9daec46f..14aad92c 100644 --- a/src/Reader/Filter/GreaterThanOrEqual.php +++ b/src/Reader/Filter/GreaterThanOrEqual.php @@ -10,8 +10,4 @@ */ final class GreaterThanOrEqual extends Compare { - public static function getOperator(): string - { - return '>='; - } } diff --git a/src/Reader/Filter/Group.php b/src/Reader/Filter/Group.php index 1f6ac3b5..8170f22f 100644 --- a/src/Reader/Filter/Group.php +++ b/src/Reader/Filter/Group.php @@ -4,92 +4,31 @@ namespace Yiisoft\Data\Reader\Filter; -use InvalidArgumentException; use Yiisoft\Data\Reader\FilterInterface; -use function array_shift; -use function is_array; -use function is_string; -use function sprintf; - /** * `Group` filter is an abstract class that allows combining multiple criteria or sub-filters. */ abstract class Group implements FilterInterface { /** - * @var array[]|FilterInterface[] Criteria and sub-filters to use. + * @var FilterInterface[] Sub-filters to use. */ - private array $filtersAndCriteria; + private array $filters; /** * @param FilterInterface ...$filters Sub-filters to use. */ public function __construct(FilterInterface ...$filters) { - $this->filtersAndCriteria = $filters; - } - - /** - * Get criteria array based on current filters and criteria. - * - * @return array Criteria array. - */ - public function toCriteriaArray(): array - { - $criteriaArray = []; - - foreach ($this->filtersAndCriteria as $filterOrCriteria) { - if ($filterOrCriteria instanceof FilterInterface) { - $filterOrCriteria = $filterOrCriteria->toCriteriaArray(); - } - - $criteriaArray[] = $filterOrCriteria; - } - - return [static::getOperator(), $criteriaArray]; + $this->filters = $filters; } /** - * Get a new instance with filters set from criteria array provided. - * - * ```php - * $dataReader->withFilter((new All())->withCriteriaArray( - * [ - * ['>', 'id', 88], - * ['or', [ - * ['=', 'state', 2], - * ['like', 'name', 'eva'], - * ], - * ] - * )); - * ``` - * - * @param array[] $criteriaArray Criteria array to use. - * Instances of FilterInterface are ignored. - * - * @throws InvalidArgumentException If criteria array is not valid. - * - * @return static New instance. - * - * @psalm-suppress DocblockTypeContradiction Needed to allow to validation of `$criteriaArray` + * @return FilterInterface[] */ - public function withCriteriaArray(array $criteriaArray): static + public function getFilters(): array { - foreach ($criteriaArray as $key => $item) { - if (!is_array($item)) { - throw new InvalidArgumentException(sprintf('Invalid filter on "%s" key.', $key)); - } - - $operator = array_shift($item); - - if (!is_string($operator) || $operator === '') { - throw new InvalidArgumentException(sprintf('Invalid filter operator on "%s" key.', $key)); - } - } - - $new = clone $this; - $new->filtersAndCriteria = $criteriaArray; - return $new; + return $this->filters; } } diff --git a/src/Reader/Filter/In.php b/src/Reader/Filter/In.php index 0ab535db..e14be733 100644 --- a/src/Reader/Filter/In.php +++ b/src/Reader/Filter/In.php @@ -4,7 +4,7 @@ namespace Yiisoft\Data\Reader\Filter; -use Yiisoft\Data\Reader\FilterAssert; +use InvalidArgumentException; use Yiisoft\Data\Reader\FilterInterface; /** @@ -21,21 +21,29 @@ final class In implements FilterInterface * @param string $field Name of the field to compare. * @param bool[]|float[]|int[]|string[] $values Values to check against. */ - public function __construct(private string $field, array $values) - { + public function __construct( + public readonly string $field, + array $values + ) { foreach ($values as $value) { - FilterAssert::isScalar($value); + /** @psalm-suppress DocblockTypeContradiction */ + if (!is_scalar($value)) { + throw new InvalidArgumentException( + sprintf( + 'The value should be scalar. "%s" is received.', + get_debug_type($value), + ) + ); + } } $this->values = $values; } - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->field, $this->values]; - } - - public static function getOperator(): string + /** + * @return bool[]|float[]|int[]|string[] + */ + public function getValues(): array { - return 'in'; + return $this->values; } } diff --git a/src/Reader/Filter/LessThan.php b/src/Reader/Filter/LessThan.php index 80f2b68f..eb2d0824 100644 --- a/src/Reader/Filter/LessThan.php +++ b/src/Reader/Filter/LessThan.php @@ -9,8 +9,4 @@ */ final class LessThan extends Compare { - public static function getOperator(): string - { - return '<'; - } } diff --git a/src/Reader/Filter/LessThanOrEqual.php b/src/Reader/Filter/LessThanOrEqual.php index 932958b2..876b60e1 100644 --- a/src/Reader/Filter/LessThanOrEqual.php +++ b/src/Reader/Filter/LessThanOrEqual.php @@ -9,8 +9,4 @@ */ final class LessThanOrEqual extends Compare { - public static function getOperator(): string - { - return '<='; - } } diff --git a/src/Reader/Filter/Like.php b/src/Reader/Filter/Like.php index 10a5e01c..ac7e36d7 100644 --- a/src/Reader/Filter/Like.php +++ b/src/Reader/Filter/Like.php @@ -15,17 +15,9 @@ final class Like implements FilterInterface * @param string $field Name of the field to compare. * @param string $value Value to like-compare with. */ - public function __construct(private string $field, private string $value) - { - } - - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->field, $this->value]; - } - - public static function getOperator(): string - { - return 'like'; + public function __construct( + public readonly string $field, + public readonly string $value, + ) { } } diff --git a/src/Reader/Filter/Not.php b/src/Reader/Filter/Not.php index fe51a220..35dba8f2 100644 --- a/src/Reader/Filter/Not.php +++ b/src/Reader/Filter/Not.php @@ -14,17 +14,8 @@ final class Not implements FilterInterface /** * @param FilterInterface $filter Filter to negate. */ - public function __construct(private FilterInterface $filter) - { - } - - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->filter->toCriteriaArray()]; - } - - public static function getOperator(): string - { - return 'not'; + public function __construct( + public readonly FilterInterface $filter + ) { } } diff --git a/src/Reader/FilterAssert.php b/src/Reader/FilterAssert.php deleted file mode 100644 index c2aa611a..00000000 --- a/src/Reader/FilterAssert.php +++ /dev/null @@ -1,91 +0,0 @@ -getFilters() as $subFilter) { + $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; + if ($filterHandler === null) { + throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class)); + } + if (!$filterHandler->match($item, $subFilter, $iterableFilterHandlers)) { + return false; + } + } + + return true; } } diff --git a/src/Reader/Iterable/FilterHandler/AnyHandler.php b/src/Reader/Iterable/FilterHandler/AnyHandler.php index 85f897b2..1dcb98d8 100644 --- a/src/Reader/Iterable/FilterHandler/AnyHandler.php +++ b/src/Reader/Iterable/FilterHandler/AnyHandler.php @@ -4,23 +4,40 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; +use InvalidArgumentException; +use LogicException; use Yiisoft\Data\Reader\Filter\Any; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; -use function in_array; /** * `Any` iterable filter handler allows combining multiple sub-filters. * The filter matches if any of the sub-filters match. */ -final class AnyHandler extends GroupHandler +final class AnyHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return Any::getOperator(); + return Any::class; } - protected function checkResults(array $results): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - return in_array(true, $results, true); + if (!$filter instanceof Any) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + foreach($filter->getFilters() as $subFilter) { + $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; + if ($filterHandler === null) { + throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class)); + } + if ($filterHandler->match($item, $subFilter, $iterableFilterHandlers)) { + return true; + } + } + + return false; } } diff --git a/src/Reader/Iterable/FilterHandler/BetweenHandler.php b/src/Reader/Iterable/FilterHandler/BetweenHandler.php index 9c8f92a4..eb7e5c89 100644 --- a/src/Reader/Iterable/FilterHandler/BetweenHandler.php +++ b/src/Reader/Iterable/FilterHandler/BetweenHandler.php @@ -8,41 +8,35 @@ use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Between; -use Yiisoft\Data\Reader\FilterAssert; +use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; -use function count; - /** * `Between` iterable filter handler checks that the item's field value * is between minimal and maximal values. */ final class BetweenHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return Between::getOperator(); + return Between::class; } - public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool + public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (count($arguments) !== 3) { - throw new InvalidArgumentException('$arguments should contain exactly three elements.'); + if (!$filter instanceof Between) { + throw new InvalidArgumentException('Incorrect filter.'); } - /** @var string $field */ - [$field, $minValue, $maxValue] = $arguments; - FilterAssert::fieldIsString($field); - - $value = ArrayHelper::getValue($item, $field); + $value = ArrayHelper::getValue($item, $filter->field); if (!$value instanceof DateTimeInterface) { - return $value >= $minValue && $value <= $maxValue; + return $value >= $filter->minValue && $value <= $filter->maxValue; } - return $minValue instanceof DateTimeInterface - && $maxValue instanceof DateTimeInterface - && $value->getTimestamp() >= $minValue->getTimestamp() - && $value->getTimestamp() <= $maxValue->getTimestamp(); + return $filter->minValue instanceof DateTimeInterface + && $filter->maxValue instanceof DateTimeInterface + && $value->getTimestamp() >= $filter->minValue->getTimestamp() + && $value->getTimestamp() <= $filter->maxValue->getTimestamp(); } } diff --git a/src/Reader/Iterable/FilterHandler/CompareHandler.php b/src/Reader/Iterable/FilterHandler/CompareHandler.php deleted file mode 100644 index ffcf7329..00000000 --- a/src/Reader/Iterable/FilterHandler/CompareHandler.php +++ /dev/null @@ -1,42 +0,0 @@ -compare(ArrayHelper::getValue($item, $field), $value); - } -} diff --git a/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php b/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php index 948ee976..014dfc3c 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php @@ -5,32 +5,29 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\EqualsEmpty; -use Yiisoft\Data\Reader\FilterAssert; +use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; -use function count; - /** * `EqualsEmpty` iterable filter handler checks that the item's field value is empty. */ final class EqualsEmptyHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return EqualsEmpty::getOperator(); + return EqualsEmpty::class; } - public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool + public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (count($arguments) !== 1) { - throw new InvalidArgumentException('$arguments should contain exactly one element.'); + if (!$filter instanceof EqualsEmpty) { + throw new InvalidArgumentException('Incorrect filter.'); } - [$field] = $arguments; - FilterAssert::fieldIsString($field); + $value = ArrayHelper::getValue($item, $filter->field); - /** @var string $field */ - return empty($item[$field]); + return empty($value); } } diff --git a/src/Reader/Iterable/FilterHandler/EqualsHandler.php b/src/Reader/Iterable/FilterHandler/EqualsHandler.php index c76f245d..a03df749 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsHandler.php @@ -5,20 +5,31 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Equals; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; /** * `Equals` iterable filter handler checks that the item's field value matches given value. */ -final class EqualsHandler extends CompareHandler +final class EqualsHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return Equals::getOperator(); + return Equals::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { + if (!$filter instanceof Equals) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->getValue(); + if (!$itemValue instanceof DateTimeInterface) { return $itemValue == $argumentValue; } diff --git a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php index 2c02ad9d..e32abdca 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php @@ -7,31 +7,25 @@ use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\EqualsNull; -use Yiisoft\Data\Reader\FilterAssert; +use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; -use function count; - /** * `EqualsNull` iterable filter handler checks that the item's field value is null. */ final class EqualsNullHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return EqualsNull::getOperator(); + return EqualsNull::class; } - public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool + public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (count($arguments) !== 1) { - throw new InvalidArgumentException('$arguments should contain exactly one element.'); + if (!$filter instanceof EqualsNull) { + throw new InvalidArgumentException('Incorrect filter.'); } - [$field] = $arguments; - FilterAssert::fieldIsString($field); - - /** @var string $field */ - return ArrayHelper::getValue($item, $field) === null; + return ArrayHelper::getValue($item, $filter->field) === null; } } diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php index eee247bc..2916c21a 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php @@ -5,20 +5,31 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\GreaterThan; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; /** * `GreaterThan` iterable filter handler checks that the item's field value is greater than the given value. */ -final class GreaterThanHandler extends CompareHandler +final class GreaterThanHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return GreaterThan::getOperator(); + return GreaterThan::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { + if (!$filter instanceof GreaterThan) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->getValue(); + if (!$itemValue instanceof DateTimeInterface) { return $itemValue > $argumentValue; } diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php index d040ac5b..77195dd2 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php @@ -5,21 +5,32 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; /** * `GreaterThanOrEqual` iterable filter handler checks that the item's field value * is greater than or equal to the given value. */ -final class GreaterThanOrEqualHandler extends CompareHandler +final class GreaterThanOrEqualHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return GreaterThanOrEqual::getOperator(); + return GreaterThanOrEqual::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { + if (!$filter instanceof GreaterThanOrEqual) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->getValue(); + if (!$itemValue instanceof DateTimeInterface) { return $itemValue >= $argumentValue; } diff --git a/src/Reader/Iterable/FilterHandler/GroupHandler.php b/src/Reader/Iterable/FilterHandler/GroupHandler.php deleted file mode 100644 index 63ee1549..00000000 --- a/src/Reader/Iterable/FilterHandler/GroupHandler.php +++ /dev/null @@ -1,90 +0,0 @@ -match($item, $subFilter, $iterableFilterHandlers); - } - - return $this->checkResults($results); - } -} diff --git a/src/Reader/Iterable/FilterHandler/InHandler.php b/src/Reader/Iterable/FilterHandler/InHandler.php index 7fe85a1d..929ca48e 100644 --- a/src/Reader/Iterable/FilterHandler/InHandler.php +++ b/src/Reader/Iterable/FilterHandler/InHandler.php @@ -4,23 +4,33 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\In; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; use function in_array; -use function is_array; /** * `In` iterable filter handler ensures that the field value matches one of the value provided. */ -final class InHandler extends CompareHandler +final class InHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return In::getOperator(); + return In::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - return is_array($argumentValue) && in_array($itemValue, $argumentValue, false); + if (!$filter instanceof In) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->getValues(); + + return in_array($itemValue, $argumentValue); } } diff --git a/src/Reader/Iterable/FilterHandler/LessThanHandler.php b/src/Reader/Iterable/FilterHandler/LessThanHandler.php index 1739d910..5e89e646 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanHandler.php @@ -5,20 +5,31 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\LessThan; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; /** * `LessThan` iterable filter handler checks that the item's field value is less than the given value. */ -final class LessThanHandler extends CompareHandler +final class LessThanHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return LessThan::getOperator(); + return LessThan::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { + if (!$filter instanceof LessThan) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->getValue(); + if (!$itemValue instanceof DateTimeInterface) { return $itemValue < $argumentValue; } diff --git a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php index a469f4be..51fc3280 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php @@ -5,21 +5,32 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; /** * `LessThanOrEqual` iterable filter handler checks that the item's field value * is less than or equal to the given value. */ -final class LessThanOrEqualHandler extends CompareHandler +final class LessThanOrEqualHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return LessThanOrEqual::getOperator(); + return LessThanOrEqual::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { + if (!$filter instanceof LessThanOrEqual) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->getValue(); + if (!$itemValue instanceof DateTimeInterface) { return $itemValue <= $argumentValue; } diff --git a/src/Reader/Iterable/FilterHandler/LikeHandler.php b/src/Reader/Iterable/FilterHandler/LikeHandler.php index d9e54552..3a5e732a 100644 --- a/src/Reader/Iterable/FilterHandler/LikeHandler.php +++ b/src/Reader/Iterable/FilterHandler/LikeHandler.php @@ -4,23 +4,35 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; +use InvalidArgumentException; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Like; +use Yiisoft\Data\Reader\FilterInterface; +use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; + use function is_string; use function stripos; /** * `Like` iterable filter handler ensures that the field value is like-match to a given value. */ -final class LikeHandler extends CompareHandler +final class LikeHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return Like::getOperator(); + return Like::class; } - protected function compare(mixed $itemValue, mixed $argumentValue): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - return is_string($itemValue) && is_string($argumentValue) && stripos($itemValue, $argumentValue) !== false; + if (!$filter instanceof Like) { + throw new InvalidArgumentException('Incorrect filter.'); + } + + $itemValue = ArrayHelper::getValue($item, $filter->field); + $argumentValue = $filter->value; + + return is_string($itemValue) && stripos($itemValue, $argumentValue) !== false; } } diff --git a/src/Reader/Iterable/FilterHandler/NotHandler.php b/src/Reader/Iterable/FilterHandler/NotHandler.php index 1c5cac25..1f97bae2 100644 --- a/src/Reader/Iterable/FilterHandler/NotHandler.php +++ b/src/Reader/Iterable/FilterHandler/NotHandler.php @@ -5,14 +5,11 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use InvalidArgumentException; +use LogicException; use Yiisoft\Data\Reader\Filter\Not; -use Yiisoft\Data\Reader\FilterAssert; +use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; -use function array_shift; -use function count; -use function is_array; -use function is_string; use function sprintf; /** @@ -20,53 +17,21 @@ */ final class NotHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return Not::getOperator(); + return Not::class; } - public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool + public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (count($arguments) !== 1) { - throw new InvalidArgumentException('$arguments should contain exactly one element.'); + if (!$filter instanceof Not) { + throw new InvalidArgumentException('Incorrect filter.'); } - [$values] = $arguments; - - if (!is_array($values)) { - throw new InvalidArgumentException(sprintf( - 'The values should be array. The %s is received.', - get_debug_type($values), - )); - } - - if (empty($values)) { - throw new InvalidArgumentException('At least operator should be provided.'); - } - - $operator = array_shift($values); - - if (!is_string($operator)) { - throw new InvalidArgumentException(sprintf( - 'The operator should be string. The %s is received.', - get_debug_type($operator), - )); - } - - if ($operator === '') { - throw new InvalidArgumentException('The operator string cannot be empty.'); - } - - /** @var mixed $filterHandler */ - $filterHandler = $iterableFilterHandlers[$operator] ?? null; - + $filterHandler = $iterableFilterHandlers[$filter->filter::class] ?? null; if ($filterHandler === null) { - throw new InvalidArgumentException(sprintf('"%s" operator is not supported.', $operator)); + throw new LogicException(sprintf('Filter "%s" is not supported.', $filter->filter::class)); } - - FilterAssert::isIterableFilterHandlerInterface($filterHandler); - /** @var IterableFilterHandlerInterface $filterHandler */ - - return !$filterHandler->match($item, $values, $iterableFilterHandlers); + return !$filterHandler->match($item, $filter->filter, $iterableFilterHandlers); } } diff --git a/src/Reader/Iterable/IterableDataReader.php b/src/Reader/Iterable/IterableDataReader.php index aa62fa01..cbc9923c 100644 --- a/src/Reader/Iterable/IterableDataReader.php +++ b/src/Reader/Iterable/IterableDataReader.php @@ -167,7 +167,6 @@ public function read(): array { $data = []; $skipped = 0; - $filter = $this->filter?->toCriteriaArray(); $sortedData = $this->sort === null ? $this->data : $this->sortItems($this->data, $this->sort); foreach ($sortedData as $key => $item) { @@ -184,7 +183,7 @@ public function read(): array } // Filter items. - if ($filter === null || $this->matchFilter($item, $filter)) { + if ($this->filter === null || $this->matchFilter($item, $this->filter)) { $data[$key] = $item; } } @@ -205,35 +204,19 @@ public function readOne(): array|object|null * Return whether an item matches iterable filter. * * @param array|object $item Item to check. - * @param array $filter Filter. + * @param FilterInterface $filter Filter. * * @return bool Whether an item matches iterable filter. */ - private function matchFilter(array|object $item, array $filter): bool + private function matchFilter(array|object $item, FilterInterface $filter): bool { - $operation = array_shift($filter); - $arguments = $filter; - - if (!is_string($operation)) { - throw new RuntimeException( - sprintf( - 'The operator should be string. The %s is received.', - get_debug_type($operation), - ) - ); - } - - if ($operation === '') { - throw new RuntimeException('The operator string cannot be empty.'); - } - - $processor = $this->iterableFilterHandlers[$operation] ?? null; + $handler = $this->iterableFilterHandlers[$filter::class] ?? null; - if ($processor === null) { - throw new RuntimeException(sprintf('Operation "%s" is not supported.', $operation)); + if ($handler === null) { + throw new RuntimeException(sprintf('Filter "%s" is not supported.', $filter::class)); } - return $processor->match($item, $arguments, $this->iterableFilterHandlers); + return $handler->match($item, $filter, $this->iterableFilterHandlers); } /** @@ -298,7 +281,7 @@ private function prepareFilterHandlers(array $filterHandlers): array ) ); } - $result[$filterHandler->getOperator()] = $filterHandler; + $result[$filterHandler->getFilterClass()] = $filterHandler; } return $result; diff --git a/src/Reader/Iterable/IterableFilterHandlerInterface.php b/src/Reader/Iterable/IterableFilterHandlerInterface.php index 3283ded2..fb3d8961 100644 --- a/src/Reader/Iterable/IterableFilterHandlerInterface.php +++ b/src/Reader/Iterable/IterableFilterHandlerInterface.php @@ -5,6 +5,7 @@ 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 @@ -17,10 +18,11 @@ interface IterableFilterHandlerInterface extends FilterHandlerInterface * for the filters with matching operator active. * * @param array|object $item Item to check. - * @param array $arguments Arguments to pass to iterable filter handlers. - * @param array $iterableFilterHandlers Iterable filter handlers to use in case it is a group filter. + * @param FilterInterface $filter Matched filter. + * @param IterableFilterHandlerInterface[] $iterableFilterHandlers Iterable filter handlers to use in case it is + * a group filter. * * @return bool Whether item matches the filter. */ - public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool; + public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool; } diff --git a/tests/Reader/Filter/AllTest.php b/tests/Reader/Filter/AllTest.php deleted file mode 100644 index beb78d04..00000000 --- a/tests/Reader/Filter/AllTest.php +++ /dev/null @@ -1,88 +0,0 @@ -assertSame([ - 'and', - [ - ['<', 'test', 4], - ['>', 'test', 2], - ], - ], $filter->toCriteriaArray()); - } - - public function testWithCriteriaArrayIsImmutable(): void - { - $filter = new All( - new LessThan('test', 4), - new GreaterThan('test', 2), - ); - - $newFilter = $filter->withCriteriaArray([ - ['>', 'test', 1], - ['<', 'test', 5], - ]); - - $this->assertNotSame($filter, $newFilter); - } - - public function testWithCriteriaArrayOverridesConstructor(): void - { - $filter = new All( - new LessThan('test', 4), - new GreaterThan('test', 2), - ); - - $newFilter = $filter->withCriteriaArray([ - ['>', 'test', 1], - ['<', 'test', 5], - ]); - - $this->assertEquals( - [ - 'and', - [ - ['>', 'test', 1], - ['<', 'test', 5], - ], - ], - $newFilter->toCriteriaArray() - ); - } - - #[DataProvider('invalidFilterDataProvider')] - public function testWithCriteriaArrayFailForInvalidFilter($filter): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid filter on "1" key.'); - - (new All())->withCriteriaArray([['=', 'test', 1], $filter]); - } - - #[DataProvider('invalidFilterOperatorDataProvider')] - public function testWithCriteriaArrayFailForInvalidFilterOperator(array $filter): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid filter operator on "0" key.'); - - (new All())->withCriteriaArray([$filter]); - } -} diff --git a/tests/Reader/Filter/AnyTest.php b/tests/Reader/Filter/AnyTest.php deleted file mode 100644 index bd93d6d4..00000000 --- a/tests/Reader/Filter/AnyTest.php +++ /dev/null @@ -1,91 +0,0 @@ -assertSame([ - 'or', - [ - ['<', 'test', 4], - ['>', 'test', 2], - ], - ], $filter->toCriteriaArray()); - } - - public function testWithCriteriaArrayIsImmutable(): void - { - $filter = new Any( - new LessThan('test', 4), - new GreaterThan('test', 2), - ); - - $newFilter = $filter->withCriteriaArray([ - ['>', 'test', 1], - ['<', 'test', 5], - ]); - - $this->assertNotSame($filter, $newFilter); - } - - public function testWithCriteriaArrayOverridesConstructor(): void - { - $filter = new Any( - new LessThan('test', 4), - new GreaterThan('test', 2), - ); - - $newFilter = $filter->withCriteriaArray([ - ['>', 'test', 1], - ['<', 'test', 5], - ]); - - $this->assertEquals( - [ - 'or', - [ - ['>', 'test', 1], - ['<', 'test', 5], - ], - ], - $newFilter->toCriteriaArray() - ); - } - - #[DataProvider('invalidFilterDataProvider')] - public function testWithCriteriaArrayFailForInvalidFilter(mixed $filter): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid filter on "1" key.'); - - (new Any())->withCriteriaArray([ - ['=', 'test', 1], - $filter, - ]); - } - - #[DataProvider('invalidFilterOperatorDataProvider')] - public function testWithCriteriaArrayFailForInvalidFilterOperator(array $filter): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid filter operator on "0" key.'); - - (new Any())->withCriteriaArray([$filter]); - } -} diff --git a/tests/Reader/Filter/BetweenTest.php b/tests/Reader/Filter/BetweenTest.php deleted file mode 100644 index 5fa94aa2..00000000 --- a/tests/Reader/Filter/BetweenTest.php +++ /dev/null @@ -1,52 +0,0 @@ -assertSame(['between', 'test', $value, $value], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidFirstValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new Between('test', $value, 2); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidSecondValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new Between('test', 1, $value); - } -} diff --git a/tests/Reader/Filter/CompareTest.php b/tests/Reader/Filter/CompareTest.php index ff4b32b4..ac5915a5 100644 --- a/tests/Reader/Filter/CompareTest.php +++ b/tests/Reader/Filter/CompareTest.php @@ -14,6 +14,6 @@ public function testWithValue() $filter = new LessThan('field', 1); $this->assertNotSame($filter, $filter->withValue(1)); - $this->assertSame(['<', 'field', 2], $filter->withValue(2)->toCriteriaArray()); + $this->assertSame(2, $filter->withValue(2)->getValue()); } } diff --git a/tests/Reader/Filter/EqualsEmptyTest.php b/tests/Reader/Filter/EqualsEmptyTest.php deleted file mode 100644 index 898140b5..00000000 --- a/tests/Reader/Filter/EqualsEmptyTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertSame(['empty', 'test'], $filter->toCriteriaArray()); - } -} diff --git a/tests/Reader/Filter/EqualsNullTest.php b/tests/Reader/Filter/EqualsNullTest.php deleted file mode 100644 index 61b7a76a..00000000 --- a/tests/Reader/Filter/EqualsNullTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertSame(['null', 'test'], $filter->toCriteriaArray()); - } -} diff --git a/tests/Reader/Filter/EqualsTest.php b/tests/Reader/Filter/EqualsTest.php deleted file mode 100644 index 71671ed7..00000000 --- a/tests/Reader/Filter/EqualsTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertSame(['=', 'test', $value], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new Equals('test', $value); - } -} diff --git a/tests/Reader/Filter/GreaterThanOrEqualTest.php b/tests/Reader/Filter/GreaterThanOrEqualTest.php deleted file mode 100644 index 1b610501..00000000 --- a/tests/Reader/Filter/GreaterThanOrEqualTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertSame(['>=', 'test', $value], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidScalarValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new GreaterThanOrEqual('test', $value); - } -} diff --git a/tests/Reader/Filter/GreaterThanTest.php b/tests/Reader/Filter/GreaterThanTest.php deleted file mode 100644 index 4fa33707..00000000 --- a/tests/Reader/Filter/GreaterThanTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertSame(['>', 'test', $value], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidScalarValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new GreaterThan('test', $value); - } -} diff --git a/tests/Reader/Filter/InTest.php b/tests/Reader/Filter/InTest.php index 4fdf94ce..cce0a6a7 100644 --- a/tests/Reader/Filter/InTest.php +++ b/tests/Reader/Filter/InTest.php @@ -2,30 +2,19 @@ declare(strict_types=1); -namespace Yiisoft\Data\Tests\Reader\Filter; +namespace Reader\Filter; use InvalidArgumentException; -use PHPUnit\Framework\Attributes\DataProvider; +use stdClass; use Yiisoft\Data\Reader\Filter\In; use Yiisoft\Data\Tests\TestCase; final class InTest extends TestCase { - public function testToArray(): void + public function testNotScalarValues(): void { - $filter = new In('test', [1, 2]); - - $this->assertSame(['in', 'test', [1, 2]], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidScalarValue($value): void - { - $type = get_debug_type($value); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The value should be scalar. The $type is received."); - - new In('test', [$value]); + $this->expectExceptionMessage('The value should be scalar. "' . stdClass::class . '" is received.'); + new In('test', [new stdClass()]); } } diff --git a/tests/Reader/Filter/LessThanOrEqualTest.php b/tests/Reader/Filter/LessThanOrEqualTest.php deleted file mode 100644 index 0af2986c..00000000 --- a/tests/Reader/Filter/LessThanOrEqualTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertSame(['<=', 'test', $value], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidScalarValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new LessThanOrEqual('test', $value); - } -} diff --git a/tests/Reader/Filter/LessThanTest.php b/tests/Reader/Filter/LessThanTest.php deleted file mode 100644 index 2d40735b..00000000 --- a/tests/Reader/Filter/LessThanTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertSame(['<', 'test', $value], $filter->toCriteriaArray()); - } - - #[DataProvider('invalidScalarValueDataProvider')] - public function testConstructorFailForInvalidScalarValue($value): void - { - $this->expectException(InvalidArgumentException::class); - - $this->expectExceptionMessage(sprintf( - 'The value should be scalar or %s instance. The %s is received.', - DateTimeInterface::class, - get_debug_type($value), - )); - - new LessThan('test', $value); - } -} diff --git a/tests/Reader/Filter/LikeTest.php b/tests/Reader/Filter/LikeTest.php deleted file mode 100644 index c14a35c2..00000000 --- a/tests/Reader/Filter/LikeTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertSame(['like', 'test', 'value'], $filter->toCriteriaArray()); - } -} diff --git a/tests/Reader/Filter/NotTest.php b/tests/Reader/Filter/NotTest.php deleted file mode 100644 index 73e80394..00000000 --- a/tests/Reader/Filter/NotTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertSame(['not', ['like', 'test', 'value']], $filter->toCriteriaArray()); - } -} diff --git a/tests/Reader/IterableDataReaderTest.php b/tests/Reader/IterableDataReaderTest.php index a5355830..4e37ebb4 100644 --- a/tests/Reader/IterableDataReaderTest.php +++ b/tests/Reader/IterableDataReaderTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Tests\Reader; use ArrayIterator; -use DateTimeInterface; use Generator; use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; @@ -21,15 +20,14 @@ use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Filter\Like; use Yiisoft\Data\Reader\Filter\Not; -use Yiisoft\Data\Reader\FilterAssert; use Yiisoft\Data\Reader\FilterHandlerInterface; use Yiisoft\Data\Reader\FilterInterface; -use Yiisoft\Data\Reader\Iterable\FilterHandler\CompareHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; use Yiisoft\Data\Reader\Sort; use Yiisoft\Data\Tests\Support\CustomFilter\Digital; use Yiisoft\Data\Tests\Support\CustomFilter\DigitalHandler; +use Yiisoft\Data\Tests\Support\CustomFilter\FilterWithoutHandler; use Yiisoft\Data\Tests\TestCase; use function array_slice; @@ -80,7 +78,7 @@ public function testImmutability(): void public function testExceptionOnPassingNonIterableFilters(): void { $nonIterableFilterHandler = new class () implements FilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { return '?'; } @@ -401,39 +399,23 @@ public function testCustomEqualsProcessor(): void $dataReader = (new IterableDataReader(self::DEFAULT_DATASET)) ->withSort($sort) - ->withFilterHandlers(new class () extends CompareHandler { - public function getOperator(): string - { - return Equals::getOperator(); - } - - protected function compare(mixed $itemValue, mixed $argumentValue): bool - { - if (!$itemValue instanceof DateTimeInterface) { - return $itemValue == $argumentValue; - } - - return $argumentValue instanceof DateTimeInterface - && $itemValue->getTimestamp() === $argumentValue->getTimestamp(); - } - - public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool - { - if (count($arguments) !== 2) { - throw new InvalidArgumentException('$arguments should contain exactly two elements.'); + ->withFilterHandlers( + new class () implements IterableFilterHandlerInterface { + public function getFilterClass(): string + { + return Equals::class; } - [$field, $value] = $arguments; - FilterAssert::fieldIsString($field); - - if ($item[$field] === 2) { - return true; + public function match( + array|object $item, + FilterInterface $filter, + array $iterableFilterHandlers + ): bool { + /** @var Equals $filter */ + return $item[$filter->field] === 2; } - - /** @var string $field */ - return array_key_exists($field, $item) && $this->compare($item[$field], $value); } - }); + ); $dataReader = $dataReader->withFilter(new Equals('id', 100)); $expected = [self::ITEM_2]; @@ -441,54 +423,13 @@ public function match(array|object $item, array $arguments, array $iterableFilte $this->assertSame($expected, array_values($this->iterableToArray($dataReader->read()))); } - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFilterFailIfOperatorIsNotString($operator): void - { - $reader = (new IterableDataReader(self::DEFAULT_DATASET)) - ->withFilter( - new class ($operator) implements FilterInterface { - public function __construct( - private mixed $operator - ) { - } - - public static function getOperator(): string - { - return 'custom-filter'; - } - - public function toCriteriaArray(): array - { - return [$this->operator, 'field', 'value']; - } - } - ); - - $type = get_debug_type($operator); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage("The operator should be string. The $type is received."); - $reader->read(); - } - - public function testNotSupportedOperator(): void - { - $dataReader = (new IterableDataReader(self::DEFAULT_DATASET)) - ->withFilter($this->createFilterWithNotSupportedOperator('---')); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Operation "---" is not supported.'); - - $dataReader->read(); - } - - public function testNotSupportedEmptyOperator(): void + public function testNotSupportedFilter(): void { $dataReader = (new IterableDataReader(self::DEFAULT_DATASET)) - ->withFilter($this->createFilterWithNotSupportedOperator('')); + ->withFilter(new FilterWithoutHandler()); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('The operator string cannot be empty.'); + $this->expectExceptionMessage('Filter "' . FilterWithoutHandler::class . '" is not supported.'); $dataReader->read(); } @@ -565,28 +506,6 @@ public function testWithLimitZero(): void ); } - private function createFilterWithNotSupportedOperator(string $operator): FilterInterface - { - return new class ($operator) implements FilterInterface { - private static string $operator; - - public function __construct(string $operator) - { - self::$operator = $operator; - } - - public static function getOperator(): string - { - return self::$operator; - } - - public function toCriteriaArray(): array - { - return [self::getOperator(), self::$operator]; - } - }; - } - private function getDataSetAsGenerator(): Generator { yield from self::DEFAULT_DATASET; diff --git a/tests/Reader/IterableHandler/AllTest.php b/tests/Reader/IterableHandler/AllTest.php index 3cd9618b..2ff21ca3 100644 --- a/tests/Reader/IterableHandler/AllTest.php +++ b/tests/Reader/IterableHandler/AllTest.php @@ -5,158 +5,92 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use InvalidArgumentException; +use LogicException; use PHPUnit\Framework\Attributes\DataProvider; -use stdClass; +use Yiisoft\Data\Reader\Filter\All; +use Yiisoft\Data\Reader\Filter\Equals; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; +use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Iterable\FilterHandler\AllHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; -use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; +use Yiisoft\Data\Tests\Support\CustomFilter\FilterWithoutHandler; use Yiisoft\Data\Tests\TestCase; final class AllTest extends TestCase { public static function matchDataProvider(): array { + $handlers = [ + Equals::class => new EqualsHandler(), + GreaterThanOrEqual::class => new GreaterThanOrEqualHandler(), + LessThanOrEqual::class => new LessThanOrEqualHandler(), + ]; + return [ [ true, - [[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], + $handlers ], [ true, - [[['=', 'value', '45'], ['>=', 'value', 45], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', '45'), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], + $handlers ], [ false, - [[['=', 'value', 44], ['>=', 'value', 45], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 44), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], + $handlers ], [ false, - [[['=', 'value', 45], ['>=', 'value', 46], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 46), new LessThanOrEqual('value', 45)], + $handlers ], [ false, - [[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 44]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 44)], + $handlers ], [ false, - [[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 44]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 44)], + $handlers ], ]; } #[DataProvider('matchDataProvider')] - public function testMatch(bool $expected, array $arguments, array $filterHandlers): void + public function testMatch(bool $expected, array $filters, array $filterHandlers): void { - $processor = new AllHandler(); + $handler = new AllHandler(); $item = [ 'id' => 1, 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, $filterHandlers)); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'two' => [[1, 2]], - 'tree' => [[1, 2]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly one element.'); - - (new AllHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidArrayValueDataProvider')] - public function testMatchFailIfSubFiltersIsNotArray($subFilters): void - { - $type = get_debug_type($subFilters); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The sub filters should be array. The $type is received."); - - (new AllHandler())->match(['id' => 1], [$subFilters], []); - } - - #[DataProvider('invalidArrayValueDataProvider')] - public function testMatchFailIfSubFilterIsNotArray($subFilters): void - { - $type = get_debug_type($subFilters); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The sub filter should be array. The $type is received."); - - (new AllHandler())->match(['id' => 1], [[$subFilters]], []); - } - - public function testMatchFailIfArgumentValueIsEmptyArray(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('At least operator should be provided.'); - - (new AllHandler())->match(['id' => 1], [[[]]], []); - } - - public static function invalidFilterOperatorDataProvider(): array - { - $data = parent::invalidFilterOperatorDataProvider(); - unset($data['array'], $data['empty-string']); - return $data; - } - - #[DataProvider('invalidFilterOperatorDataProvider')] - public function testMatchFailForInvalidFilterOperator(array $filter): void - { - $type = get_debug_type($filter[0]); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The operator should be string. The $type is received."); - - (new AllHandler())->match(['id' => 1], [[$filter]], []); - } - - public function testMatchFailForEmptyFilterOperator(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The operator string cannot be empty.'); - - (new AllHandler())->match(['id' => 1], [[['']]], []); + $this->assertSame($expected, $handler->match($item, new All(...$filters), $filterHandlers)); } public function testMatchFailIfFilterOperatorIsNotSupported(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('">" operator is not supported.'); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Filter "' . FilterWithoutHandler::class . '" is not supported.'); - (new AllHandler())->match(['id' => 1], [[['>']]], ['=' => new EqualsHandler()]); + (new AllHandler())->match(['id' => 1], new All(new FilterWithoutHandler()), []); } - public function testMatchFailIfFilterHandlerIsNotIterable(): void + public function testInvalidFilter(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf( - 'The filter handler should be an object and implement "%s". The %s is received.', - IterableFilterHandlerInterface::class, - stdClass::class, - )); + $handler = new AllHandler(); + $filter = new EqualsEmpty('test'); - (new AllHandler())->match(['id' => 1], [[['=']]], ['=' => new stdClass()]); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/AnyTest.php b/tests/Reader/IterableHandler/AnyTest.php index 0e74e41e..80ce4917 100644 --- a/tests/Reader/IterableHandler/AnyTest.php +++ b/tests/Reader/IterableHandler/AnyTest.php @@ -5,60 +5,67 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use InvalidArgumentException; +use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use stdClass; +use Yiisoft\Data\Reader\Filter\Any; +use Yiisoft\Data\Reader\Filter\Equals; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; +use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Iterable\FilterHandler\AnyHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; +use Yiisoft\Data\Tests\Support\CustomFilter\FilterWithoutHandler; use Yiisoft\Data\Tests\TestCase; final class AnyTest extends TestCase { public static function matchDataProvider(): array { + $handlers = [ + Equals::class => new EqualsHandler(), + GreaterThanOrEqual::class => new GreaterThanOrEqualHandler(), + LessThanOrEqual::class => new LessThanOrEqualHandler(), + ]; return [ [ true, - [[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], - ], - [ - true, - [[['=', 'value', '45'], ['>=', 'value', 45], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], + $handlers ], [ true, - [[['=', 'value', 44], ['>=', 'value', 45], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', '45'), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], + $handlers ], [ true, - [[['=', 'value', 45], ['>=', 'value', 46], ['<=', 'value', 45]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], + $handlers ], [ true, - [[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 44]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 46), new LessThanOrEqual('value', 45)], + $handlers ], [ true, - [[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 44]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 44)], + $handlers ], [ false, - [[['=', 'value', 44], ['>=', 'value', 46], ['<=', 'value', 44]]], - ['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()], + [new Equals('value', 44), new GreaterThanOrEqual('value', 46), new LessThanOrEqual('value', 44)], + $handlers ], ]; } #[DataProvider('matchDataProvider')] - public function testMatch(bool $expected, array $arguments, array $filterHandlers): void + public function testMatch(bool $expected, array $filters, array $filterHandlers): void { $handler = new AnyHandler(); @@ -67,101 +74,24 @@ public function testMatch(bool $expected, array $arguments, array $filterHandler 'value' => 45, ]; - $this->assertSame($expected, $handler->match($item, $arguments, $filterHandlers)); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'two' => [[1, 2]], - 'tree' => [[1, 2]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly one element.'); - - (new AnyHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidArrayValueDataProvider')] - public function testMatchFailIfSubFiltersIsNotArray($subFilters): void - { - $type = get_debug_type($subFilters); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The sub filters should be array. The $type is received."); - - (new AnyHandler())->match(['id' => 1], [$subFilters], []); - } - - #[DataProvider('invalidArrayValueDataProvider')] - public function testMatchFailIfSubFilterIsNotArray($subFilters): void - { - $type = get_debug_type($subFilters); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The sub filter should be array. The $type is received."); - - (new AnyHandler())->match(['id' => 1], [[$subFilters]], []); - } - - public function testMatchFailIfArgumentValueIsEmptyArray(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('At least operator should be provided.'); - - (new AnyHandler())->match(['id' => 1], [[[]]], []); - } - - public static function invalidFilterOperatorDataProvider(): array - { - $data = parent::invalidFilterOperatorDataProvider(); - unset($data['array'], $data['empty-string']); - return $data; - } - - #[DataProvider('invalidFilterOperatorDataProvider')] - public function testMatchFailForInvalidFilterOperator(array $filter): void - { - $type = get_debug_type($filter[0]); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The operator should be string. The $type is received."); - - (new AnyHandler())->match(['id' => 1], [[$filter]], []); - } - - public function testMatchFailForEmptyFilterOperator(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The operator string cannot be empty.'); - - (new AnyHandler())->match(['id' => 1], [[['']]], []); + $this->assertSame($expected, $handler->match($item, new Any(...$filters), $filterHandlers)); } public function testMatchFailIfFilterOperatorIsNotSupported(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('">" operator is not supported.'); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Filter "' . FilterWithoutHandler::class . '" is not supported.'); - (new AnyHandler())->match(['id' => 1], [[['>']]], ['=' => new EqualsHandler()]); + (new AnyHandler())->match(['id' => 1], new Any(new FilterWithoutHandler()), []); } - public function testMatchFailIfFilterHandlerIsNotIterable(): void + public function testInvalidFilter(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf( - 'The filter handler should be an object and implement "%s". The %s is received.', - IterableFilterHandlerInterface::class, - stdClass::class, - )); + $handler = new AnyHandler(); + $filter = new EqualsEmpty('test'); - (new AnyHandler())->match(['id' => 1], [[['=']]], ['=' => new stdClass()]); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/BetweenTest.php b/tests/Reader/IterableHandler/BetweenTest.php index 88cfc64e..1d4166df 100644 --- a/tests/Reader/IterableHandler/BetweenTest.php +++ b/tests/Reader/IterableHandler/BetweenTest.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\Between; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Iterable\FilterHandler\BetweenHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; @@ -18,40 +19,40 @@ final class BetweenTest extends TestCase public static function matchScalarDataProvider(): array { return [ - [true, ['value', 42, 47]], - [true, ['value', 45, 45]], - [true, ['value', 45, 46]], - [false, ['value', 46, 47]], - [false, ['value', 46, 45]], + [true, new Between('value', 42, 47)], + [true, new Between('value', 45, 45)], + [true, new Between('value', 45, 46)], + [false, new Between('value', 46, 47)], + [false, new Between('value', 46, 45)], ]; } #[DataProvider('matchScalarDataProvider')] - public function testMatchScalar(bool $expected, array $arguments): void + public function testMatchScalar(bool $expected, Between $filter): void { - $processor = new BetweenHandler(); + $handler = new BetweenHandler(); $item = [ 'id' => 1, 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $handler->match($item, $filter, [])); } public static function matchDateTimeInterfaceDataProvider(): array { return [ - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:42'), new DateTimeImmutable('2022-02-22 16:00:47')]], - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:45'), new DateTimeImmutable('2022-02-22 16:00:45')]], - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:45'), new DateTimeImmutable('2022-02-22 16:00:46')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:46'), new DateTimeImmutable('2022-02-22 16:00:47')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:46'), new DateTimeImmutable('2022-02-22 16:00:45')]], + [true, new DateTimeImmutable('2022-02-22 16:00:42'), new DateTimeImmutable('2022-02-22 16:00:47')], + [true, new DateTimeImmutable('2022-02-22 16:00:45'), new DateTimeImmutable('2022-02-22 16:00:45')], + [true, new DateTimeImmutable('2022-02-22 16:00:45'), new DateTimeImmutable('2022-02-22 16:00:46')], + [false, new DateTimeImmutable('2022-02-22 16:00:46'), new DateTimeImmutable('2022-02-22 16:00:47')], + [false, new DateTimeImmutable('2022-02-22 16:00:46'), new DateTimeImmutable('2022-02-22 16:00:45')], ]; } #[DataProvider('matchDateTimeInterfaceDataProvider')] - public function testMatchDateTimeInterface(bool $expected, array $arguments): void + public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $from, DateTimeImmutable $to): void { $processor = new BetweenHandler(); @@ -60,37 +61,7 @@ public function testMatchDateTimeInterface(bool $expected, array $arguments): vo 'value' => new DateTimeImmutable('2022-02-22 16:00:45'), ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'two' => [[1, 2]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly three elements.'); - - (new BetweenHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new BetweenHandler())->match(['id' => 1], [$field, 1, 2], []); + $this->assertSame($expected, $processor->match($item, new Between('value', $from, $to), [])); } public function testObjectWithGetters(): void @@ -113,4 +84,14 @@ public function testObjectWithGetters(): void $this->assertSame([3 => $car3, 4 => $car4, 5 => $car5], $result); } + + public function testInvalidFilter(): void + { + $handler = new BetweenHandler(); + $filter = new EqualsEmpty('test'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); + } } diff --git a/tests/Reader/IterableHandler/EqualsEmptyTest.php b/tests/Reader/IterableHandler/EqualsEmptyTest.php index 37b32358..4486d413 100644 --- a/tests/Reader/IterableHandler/EqualsEmptyTest.php +++ b/tests/Reader/IterableHandler/EqualsEmptyTest.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\EqualsNull; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsEmptyHandler; use Yiisoft\Data\Tests\TestCase; @@ -29,36 +31,16 @@ public static function matchDataProvider(): array #[DataProvider('matchDataProvider')] public function testMatch(bool $expected, array $item): void { - $this->assertSame($expected, (new EqualsEmptyHandler())->match($item, ['value'], [])); + $this->assertSame($expected, (new EqualsEmptyHandler())->match($item, new EqualsEmpty('value'), [])); } - public static function invalidCountArgumentsDataProvider(): array + public function testInvalidFilter(): void { - return [ - 'zero' => [[]], - 'two' => [[1, 2]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } + $handler = new EqualsEmptyHandler(); + $filter = new EqualsNull('test'); - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly one element.'); - - (new EqualsEmptyHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new EqualsEmptyHandler())->match(['id' => 1], [$field], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/EqualsNullTest.php b/tests/Reader/IterableHandler/EqualsNullTest.php index 2549cdba..059c6f01 100644 --- a/tests/Reader/IterableHandler/EqualsNullTest.php +++ b/tests/Reader/IterableHandler/EqualsNullTest.php @@ -6,7 +6,9 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\EqualsNull; +use Yiisoft\Data\Reader\Iterable\FilterHandler\AnyHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNullHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; @@ -31,37 +33,7 @@ public static function matchDataProvider(): array #[DataProvider('matchDataProvider')] public function testMatch(bool $expected, array $item): void { - $this->assertSame($expected, (new EqualsNullHandler())->match($item, ['value'], [])); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'two' => [[1, 2]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly one element.'); - - (new EqualsNullHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new EqualsNullHandler())->match(['id' => 1], [$field], []); + $this->assertSame($expected, (new EqualsNullHandler())->match($item, new EqualsNull('value'), [])); } public function testObjectWithGetters(): void @@ -84,4 +56,14 @@ public function testObjectWithGetters(): void $this->assertSame([3 => $car3, 5 => $car5], $result); } + + public function testInvalidFilter(): void + { + $handler = new EqualsNullHandler(); + $filter = new EqualsEmpty('test'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); + } } diff --git a/tests/Reader/IterableHandler/EqualsTest.php b/tests/Reader/IterableHandler/EqualsTest.php index 9257edbd..c172700e 100644 --- a/tests/Reader/IterableHandler/EqualsTest.php +++ b/tests/Reader/IterableHandler/EqualsTest.php @@ -8,7 +8,9 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\Equals; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; +use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNullHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; use Yiisoft\Data\Tests\TestCase; @@ -18,15 +20,15 @@ final class EqualsTest extends TestCase public static function matchScalarDataProvider(): array { return [ - [true, ['value', 45]], - [true, ['value', '45']], - [false, ['value', 44]], - [false, ['value', 46]], + [true, 45], + [true, '45'], + [false, 44], + [false, 46], ]; } #[DataProvider('matchScalarDataProvider')] - public function testMatchScalar(bool $expected, array $arguments): void + public function testMatchScalar(bool $expected, mixed $value): void { $processor = new EqualsHandler(); @@ -35,59 +37,29 @@ public function testMatchScalar(bool $expected, array $arguments): void 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $processor->match($item, new Equals('value', $value), [])); } public static function matchDateTimeInterfaceDataProvider(): array { return [ - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:45')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:44')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:46')]], + [true, new DateTimeImmutable('2022-02-22 16:00:45')], + [false, new DateTimeImmutable('2022-02-22 16:00:44')], + [false, new DateTimeImmutable('2022-02-22 16:00:46')], ]; } #[DataProvider('matchDateTimeInterfaceDataProvider')] - public function testMatchDateTimeInterface(bool $expected, array $arguments): void + public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $value): void { - $processor = new EqualsHandler(); + $handler = new EqualsHandler(); $item = [ 'id' => 1, 'value' => new DateTimeImmutable('2022-02-22 16:00:45'), ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new EqualsHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new EqualsHandler())->match(['id' => 1], [$field, 1], []); + $this->assertSame($expected, $handler->match($item, new Equals('value', $value), [])); } public function testObjectWithGetters(): void @@ -110,4 +82,14 @@ public function testObjectWithGetters(): void $this->assertSame([1 => $car1, 3 => $car3], $result); } + + public function testInvalidFilter(): void + { + $handler = new EqualsHandler(); + $filter = new EqualsEmpty('test'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); + } } diff --git a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php index 07492fd0..921316be 100644 --- a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php @@ -7,6 +7,9 @@ use DateTimeImmutable; use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; +use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; @@ -15,15 +18,15 @@ final class GreaterThanOrEqualTest extends TestCase public static function matchScalarDataProvider(): array { return [ - [true, ['value', 44]], - [true, ['value', 45]], - [true, ['value', '45']], - [false, ['value', 46]], + [true, 44], + [true, 45], + [true, '45'], + [false, 46], ]; } #[DataProvider('matchScalarDataProvider')] - public function testMatchScalar(bool $expected, array $arguments): void + public function testMatchScalar(bool $expected, mixed $value): void { $processor = new GreaterThanOrEqualHandler(); @@ -32,20 +35,20 @@ public function testMatchScalar(bool $expected, array $arguments): void 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $processor->match($item, new GreaterThanOrEqual('value', $value), [])); } public static function matchDateTimeInterfaceDataProvider(): array { return [ - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:44')]], - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:45')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:46')]], + [true, new DateTimeImmutable('2022-02-22 16:00:44')], + [true, new DateTimeImmutable('2022-02-22 16:00:45')], + [false, new DateTimeImmutable('2022-02-22 16:00:46')], ]; } #[DataProvider('matchDateTimeInterfaceDataProvider')] - public function testMatchDateTimeInterface(bool $expected, array $arguments): void + public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $value): void { $processor = new GreaterThanOrEqualHandler(); @@ -54,36 +57,16 @@ public function testMatchDateTimeInterface(bool $expected, array $arguments): vo 'value' => new DateTimeImmutable('2022-02-22 16:00:45'), ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $processor->match($item, new GreaterThanOrEqual('value', $value), [])); } - public static function invalidCountArgumentsDataProvider(): array + public function testInvalidFilter(): void { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } + $handler = new GreaterThanOrEqualHandler(); + $filter = new EqualsEmpty('test'); - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new GreaterThanOrEqualHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new GreaterThanOrEqualHandler())->match(['id' => 1], [$field, 1], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/GreaterThanTest.php b/tests/Reader/IterableHandler/GreaterThanTest.php index f64cf38d..892af8de 100644 --- a/tests/Reader/IterableHandler/GreaterThanTest.php +++ b/tests/Reader/IterableHandler/GreaterThanTest.php @@ -7,6 +7,8 @@ use DateTimeImmutable; use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\GreaterThan; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanHandler; use Yiisoft\Data\Tests\TestCase; @@ -15,75 +17,55 @@ final class GreaterThanTest extends TestCase public static function matchScalarDataProvider(): array { return [ - [true, ['value', 44]], - [true, ['value', '44']], - [false, ['value', 45]], - [false, ['value', 46]], + [true, 44], + [true, '44'], + [false, 45], + [false, 46], ]; } #[DataProvider('matchScalarDataProvider')] - public function testMatchScalar(bool $expected, array $arguments): void + public function testMatchScalar(bool $expected, mixed $value): void { - $processor = new GreaterThanHandler(); + $handler = new GreaterThanHandler(); $item = [ 'id' => 1, 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $handler->match($item, new GreaterThan('value', $value), [])); } public static function matchDateTimeInterfaceDataProvider(): array { return [ - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:44')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:45')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:46')]], + [true, new DateTimeImmutable('2022-02-22 16:00:44')], + [false, new DateTimeImmutable('2022-02-22 16:00:45')], + [false, new DateTimeImmutable('2022-02-22 16:00:46')], ]; } #[DataProvider('matchDateTimeInterfaceDataProvider')] - public function testMatchDateTimeInterface(bool $expected, array $arguments): void + public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $value): void { - $processor = new GreaterThanHandler(); + $handler = new GreaterThanHandler(); $item = [ 'id' => 1, 'value' => new DateTimeImmutable('2022-02-22 16:00:45'), ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $handler->match($item, new GreaterThan('value', $value), [])); } - public static function invalidCountArgumentsDataProvider(): array + public function testInvalidFilter(): void { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } + $handler = new GreaterThanHandler(); + $filter = new EqualsEmpty('test'); - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new GreaterThanHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new GreaterThanHandler())->match(['id' => 1], [$field, 1], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/InTest.php b/tests/Reader/IterableHandler/InTest.php index 0ea1053a..3a65c597 100644 --- a/tests/Reader/IterableHandler/InTest.php +++ b/tests/Reader/IterableHandler/InTest.php @@ -6,6 +6,9 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\In; +use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\InHandler; use Yiisoft\Data\Tests\TestCase; @@ -14,52 +17,32 @@ final class InTest extends TestCase public static function matchDataProvider(): array { return [ - [true, ['value', [44, 45, 46]]], - [true, ['value', [44, '45', 46]]], - [false, ['value', [1, 2, 3]]], + [true, [44, 45, 46]], + [true, [44, '45', 46]], + [false, [1, 2, 3]], ]; } #[DataProvider('matchDataProvider')] - public function testMatch(bool $expected, array $arguments): void + public function testMatch(bool $expected, array $value): void { - $processor = new InHandler(); + $handler = new InHandler(); $item = [ 'id' => 1, 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $handler->match($item, new In('value', $value), [])); } - public static function invalidCountArgumentsDataProvider(): array + public function testInvalidFilter(): void { - return [ - 'zero' => [[]], - 'one' => [[[]]], - 'three' => [[[], [], []]], - 'four' => [[[], [], [], []]], - ]; - } + $handler = new InHandler(); + $filter = new EqualsEmpty('test'); - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new InHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new InHandler())->match(['id' => 1], [$field, [1, 2, 3]], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/LessThanOrEqualTest.php b/tests/Reader/IterableHandler/LessThanOrEqualTest.php index fe3e08eb..8031a87a 100644 --- a/tests/Reader/IterableHandler/LessThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/LessThanOrEqualTest.php @@ -7,6 +7,9 @@ use DateTimeImmutable; use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\LessThanOrEqual; +use Yiisoft\Data\Reader\Iterable\FilterHandler\InHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; @@ -15,75 +18,55 @@ final class LessThanOrEqualTest extends TestCase public static function matchScalarDataProvider(): array { return [ - [true, ['value', 46]], - [true, ['value', 45]], - [true, ['value', '45']], - [false, ['value', 44]], + [true, 46], + [true, 45], + [true, '45'], + [false, 44], ]; } #[DataProvider('matchScalarDataProvider')] - public function testMatchScalar(bool $expected, array $arguments): void + public function testMatchScalar(bool $expected, mixed $value): void { - $processor = new LessThanOrEqualHandler(); + $handler = new LessThanOrEqualHandler(); $item = [ 'id' => 1, 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $handler->match($item, new LessThanOrEqual('value', $value), [])); } public static function matchDateTimeInterfaceDataProvider(): array { return [ - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:46')]], - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:45')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:44')]], + [true, new DateTimeImmutable('2022-02-22 16:00:46')], + [true, new DateTimeImmutable('2022-02-22 16:00:45')], + [false, new DateTimeImmutable('2022-02-22 16:00:44')], ]; } #[DataProvider('matchDateTimeInterfaceDataProvider')] - public function testMatchDateTimeInterface(bool $expected, array $arguments): void + public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $value): void { - $processor = new LessThanOrEqualHandler(); + $handler = new LessThanOrEqualHandler(); $item = [ 'id' => 1, 'value' => new DateTimeImmutable('2022-02-22 16:00:45'), ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $handler->match($item, new LessThanOrEqual('value', $value), [])); } - public static function invalidCountArgumentsDataProvider(): array + public function testInvalidFilter(): void { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } + $handler = new LessThanOrEqualHandler(); + $filter = new EqualsEmpty('test'); - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new LessThanOrEqualHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new LessThanOrEqualHandler())->match(['id' => 1], [$field, 1], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/LessThanTest.php b/tests/Reader/IterableHandler/LessThanTest.php index 0a3f1d17..25c37578 100644 --- a/tests/Reader/IterableHandler/LessThanTest.php +++ b/tests/Reader/IterableHandler/LessThanTest.php @@ -7,7 +7,10 @@ use DateTimeImmutable; use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\LessThan; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanHandler; +use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; final class LessThanTest extends TestCase @@ -15,15 +18,15 @@ final class LessThanTest extends TestCase public static function matchScalarDataProvider(): array { return [ - [true, ['value', 46]], - [true, ['value', '46']], - [false, ['value', 45]], - [false, ['value', 44]], + [true, 46], + [true, '46'], + [false, 45], + [false, 44], ]; } #[DataProvider('matchScalarDataProvider')] - public function testMatchScalar(bool $expected, array $arguments): void + public function testMatchScalar(bool $expected, mixed $value): void { $processor = new LessThanHandler(); @@ -32,58 +35,38 @@ public function testMatchScalar(bool $expected, array $arguments): void 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $processor->match($item, new LessThan('value', $value), [])); } public static function matchDateTimeInterfaceDataProvider(): array { return [ - [true, ['value', new DateTimeImmutable('2022-02-22 16:00:46')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:45')]], - [false, ['value', new DateTimeImmutable('2022-02-22 16:00:44')]], + [true, new DateTimeImmutable('2022-02-22 16:00:46')], + [false, new DateTimeImmutable('2022-02-22 16:00:45')], + [false, new DateTimeImmutable('2022-02-22 16:00:44')], ]; } #[DataProvider('matchDateTimeInterfaceDataProvider')] - public function testMatchDateTimeInterface(bool $expected, array $arguments): void + public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $value): void { - $processor = new LessThanHandler(); + $handler = new LessThanHandler(); $item = [ 'id' => 1, 'value' => new DateTimeImmutable('2022-02-22 16:00:45'), ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new LessThanHandler())->match(['id' => 1], $arguments, []); + $this->assertSame($expected, $handler->match($item, new LessThan('value', $value), [])); } - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void + public function testInvalidFilter(): void { - $type = get_debug_type($field); + $handler = new LessThanHandler(); + $filter = new EqualsEmpty('test'); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new LessThanHandler())->match(['id' => 1], [$field, 1], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/LikeTest.php b/tests/Reader/IterableHandler/LikeTest.php index 953c59d9..a3755204 100644 --- a/tests/Reader/IterableHandler/LikeTest.php +++ b/tests/Reader/IterableHandler/LikeTest.php @@ -6,6 +6,9 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\Like; +use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler; use Yiisoft\Data\Tests\TestCase; @@ -14,15 +17,14 @@ final class LikeTest extends TestCase public static function matchDataProvider(): array { return [ - [true, ['value', 'Great Cat Fighter']], - [true, ['value', 'Cat']], - [false, ['id', 1]], - [false, ['id', '1']], + [true, 'value', 'Great Cat Fighter'], + [true, 'value', 'Cat'], + [false, 'id', '1'], ]; } #[DataProvider('matchDataProvider')] - public function testMatch(bool $expected, array $arguments): void + public function testMatch(bool $expected, string $field, string $value): void { $processor = new LikeHandler(); @@ -31,36 +33,16 @@ public function testMatch(bool $expected, array $arguments): void 'value' => 'Great Cat Fighter', ]; - $this->assertSame($expected, $processor->match($item, $arguments, [])); + $this->assertSame($expected, $processor->match($item, new Like($field, $value), [])); } - public static function invalidCountArgumentsDataProvider(): array + public function testInvalidFilter(): void { - return [ - 'zero' => [[]], - 'one' => [[1]], - 'three' => [[1, 2, 3]], - 'four' => [[1, 2, 3, 4]], - ]; - } + $handler = new LikeHandler(); + $filter = new EqualsEmpty('test'); - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly two elements.'); - - (new LikeHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidStringValueDataProvider')] - public function testMatchFailForInvalidFieldValue($field): void - { - $type = get_debug_type($field); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The field should be string. The $type is received."); - - (new LikeHandler())->match(['id' => 1], [$field, 1], []); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Reader/IterableHandler/NotTest.php b/tests/Reader/IterableHandler/NotTest.php index b649f506..067622ea 100644 --- a/tests/Reader/IterableHandler/NotTest.php +++ b/tests/Reader/IterableHandler/NotTest.php @@ -5,11 +5,17 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use InvalidArgumentException; +use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use stdClass; +use Yiisoft\Data\Reader\Filter\Equals; +use Yiisoft\Data\Reader\Filter\EqualsEmpty; +use Yiisoft\Data\Reader\Filter\Not; +use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; +use Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\NotHandler; -use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; +use Yiisoft\Data\Tests\Support\CustomFilter\FilterWithoutHandler; use Yiisoft\Data\Tests\TestCase; final class NotTest extends TestCase @@ -17,15 +23,15 @@ final class NotTest extends TestCase public static function matchDataProvider(): array { return [ - [true, [['=', 'value', 44]], ['=' => new EqualsHandler()]], - [true, [['=', 'value', 46]], ['=' => new EqualsHandler()]], - [false, [['=', 'value', 45]], ['=' => new EqualsHandler()]], - [false, [['=', 'value', '45']], ['=' => new EqualsHandler()]], + [true, new Equals('value', 44), [Equals::class => new EqualsHandler()]], + [true, new Equals('value', 46), [Equals::class => new EqualsHandler()]], + [false, new Equals('value', 45), [Equals::class => new EqualsHandler()]], + [false, new Equals('value', '45'), [Equals::class => new EqualsHandler()]], ]; } #[DataProvider('matchDataProvider')] - public function testMatch(bool $expected, array $arguments, array $filterHandlers): void + public function testMatch(bool $expected, FilterInterface $filter, array $filterHandlers): void { $processor = new NotHandler(); @@ -34,90 +40,24 @@ public function testMatch(bool $expected, array $arguments, array $filterHandler 'value' => 45, ]; - $this->assertSame($expected, $processor->match($item, $arguments, $filterHandlers)); - } - - public static function invalidCountArgumentsDataProvider(): array - { - return [ - 'zero' => [[]], - 'two' => [[1, 2]], - 'tree' => [[1, 2]], - 'four' => [[1, 2, 3, 4]], - ]; - } - - #[DataProvider('invalidCountArgumentsDataProvider')] - public function testMatchFailForInvalidCountArguments($arguments): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('$arguments should contain exactly one element.'); - - (new NotHandler())->match(['id' => 1], $arguments, []); - } - - #[DataProvider('invalidArrayValueDataProvider')] - public function testMatchFailIfArgumentValueIsNotArray($value): void - { - $type = get_debug_type($value); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The values should be array. The $type is received."); - - (new NotHandler())->match(['id' => 1], [$value], []); - } - - public function testMatchFailIfArgumentValueIsEmptyArray(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('At least operator should be provided.'); - - (new NotHandler())->match(['id' => 1], [[]], []); - } - - public static function invalidFilterOperatorDataProvider(): array - { - $data = parent::invalidFilterOperatorDataProvider(); - unset($data['array'], $data['empty-string']); - return $data; - } - - #[DataProvider('invalidFilterOperatorDataProvider')] - public function testMatchFailForInvalidFilterOperator(array $filter): void - { - $type = get_debug_type($filter[0]); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The operator should be string. The $type is received."); - - (new NotHandler())->match(['id' => 1], [$filter], []); - } - - public function testMatchFailForEmptyFilterOperator(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The operator string cannot be empty.'); - - (new NotHandler())->match(['id' => 1], [['']], []); + $this->assertSame($expected, $processor->match($item, new Not($filter), $filterHandlers)); } public function testMatchFailIfFilterOperatorIsNotSupported(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('">" operator is not supported.'); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Filter "' . FilterWithoutHandler::class . '" is not supported.'); - (new NotHandler())->match(['id' => 1], [['>']], ['=' => new EqualsHandler()]); + (new NotHandler())->match(['id' => 1], new Not(new FilterWithoutHandler()), []); } - public function testMatchFailIfFilterHandlerIsNotIterable(): void + public function testInvalidFilter(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf( - 'The filter handler should be an object and implement "%s". The %s is received.', - IterableFilterHandlerInterface::class, - stdClass::class, - )); + $handler = new NotHandler(); + $filter = new EqualsEmpty('test'); - (new NotHandler())->match(['id' => 1], [['=']], ['=' => new stdClass()]); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Incorrect filter.'); + $handler->match([], $filter, []); } } diff --git a/tests/Support/CustomFilter/Digital.php b/tests/Support/CustomFilter/Digital.php index 191c2158..0b1cb3c5 100644 --- a/tests/Support/CustomFilter/Digital.php +++ b/tests/Support/CustomFilter/Digital.php @@ -8,17 +8,7 @@ final class Digital implements FilterInterface { - public function __construct(private string $field) + public function __construct(public readonly string $field) { } - - public function toCriteriaArray(): array - { - return [self::getOperator(), $this->field]; - } - - public static function getOperator(): string - { - return 'digital'; - } } diff --git a/tests/Support/CustomFilter/DigitalHandler.php b/tests/Support/CustomFilter/DigitalHandler.php index 6a5a6b89..033cd33c 100644 --- a/tests/Support/CustomFilter/DigitalHandler.php +++ b/tests/Support/CustomFilter/DigitalHandler.php @@ -5,17 +5,19 @@ namespace Yiisoft\Data\Tests\Support\CustomFilter; use Yiisoft\Arrays\ArrayHelper; +use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; final class DigitalHandler implements IterableFilterHandlerInterface { - public function getOperator(): string + public function getFilterClass(): string { - return Digital::getOperator(); + return Digital::class; } - public function match(object|array $item, array $arguments, array $iterableFilterHandlers): bool + public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - return ctype_digit((string) ArrayHelper::getValue($item, $arguments[0])); + /** @var Digital $filter */ + return ctype_digit((string) ArrayHelper::getValue($item, $filter->field)); } } diff --git a/tests/Support/CustomFilter/FilterWithoutHandler.php b/tests/Support/CustomFilter/FilterWithoutHandler.php new file mode 100644 index 00000000..e507f0d9 --- /dev/null +++ b/tests/Support/CustomFilter/FilterWithoutHandler.php @@ -0,0 +1,11 @@ + [[]], - 'bool-true' => [true], - 'bool-false' => [false], - 'callback' => [fn () => null], - 'float' => [1.0], - 'int' => [1], - 'null' => [null], - 'object' => [new stdClass()], - ]; - } - public static function invalidFilterDataProvider(): array { return [ From d71a915caf76b1d82de1eecf6b1fada1e276ee59 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 24 Feb 2024 08:49:29 +0000 Subject: [PATCH 2/8] Apply fixes from StyleCI --- src/Reader/Iterable/FilterHandler/AllHandler.php | 2 +- src/Reader/Iterable/FilterHandler/AnyHandler.php | 3 +-- src/Reader/Iterable/IterableDataReader.php | 2 -- tests/Reader/IterableDataReaderTest.php | 1 - tests/Reader/IterableHandler/AllTest.php | 12 ++++++------ tests/Reader/IterableHandler/AnyTest.php | 14 ++++++-------- tests/Reader/IterableHandler/EqualsNullTest.php | 1 - tests/Reader/IterableHandler/EqualsTest.php | 1 - .../IterableHandler/GreaterThanOrEqualTest.php | 1 - tests/Reader/IterableHandler/InTest.php | 1 - .../Reader/IterableHandler/LessThanOrEqualTest.php | 1 - tests/Reader/IterableHandler/LessThanTest.php | 1 - tests/Reader/IterableHandler/LikeTest.php | 1 - tests/Reader/IterableHandler/NotTest.php | 2 -- 14 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/Reader/Iterable/FilterHandler/AllHandler.php b/src/Reader/Iterable/FilterHandler/AllHandler.php index ae20a45a..811f2d71 100644 --- a/src/Reader/Iterable/FilterHandler/AllHandler.php +++ b/src/Reader/Iterable/FilterHandler/AllHandler.php @@ -28,7 +28,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab throw new InvalidArgumentException('Incorrect filter.'); } - foreach($filter->getFilters() as $subFilter) { + foreach ($filter->getFilters() as $subFilter) { $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; if ($filterHandler === null) { throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class)); diff --git a/src/Reader/Iterable/FilterHandler/AnyHandler.php b/src/Reader/Iterable/FilterHandler/AnyHandler.php index 1dcb98d8..d69d363b 100644 --- a/src/Reader/Iterable/FilterHandler/AnyHandler.php +++ b/src/Reader/Iterable/FilterHandler/AnyHandler.php @@ -10,7 +10,6 @@ use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; - /** * `Any` iterable filter handler allows combining multiple sub-filters. * The filter matches if any of the sub-filters match. @@ -28,7 +27,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab throw new InvalidArgumentException('Incorrect filter.'); } - foreach($filter->getFilters() as $subFilter) { + foreach ($filter->getFilters() as $subFilter) { $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; if ($filterHandler === null) { throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class)); diff --git a/src/Reader/Iterable/IterableDataReader.php b/src/Reader/Iterable/IterableDataReader.php index cbc9923c..626ec211 100644 --- a/src/Reader/Iterable/IterableDataReader.php +++ b/src/Reader/Iterable/IterableDataReader.php @@ -29,9 +29,7 @@ use Yiisoft\Data\Reader\Sort; use function array_merge; -use function array_shift; use function count; -use function is_string; use function iterator_to_array; use function sprintf; use function uasort; diff --git a/tests/Reader/IterableDataReaderTest.php b/tests/Reader/IterableDataReaderTest.php index 4e37ebb4..a3ca63e2 100644 --- a/tests/Reader/IterableDataReaderTest.php +++ b/tests/Reader/IterableDataReaderTest.php @@ -7,7 +7,6 @@ use ArrayIterator; use Generator; use InvalidArgumentException; -use PHPUnit\Framework\Attributes\DataProvider; use RuntimeException; use Yiisoft\Data\Reader\DataReaderException; use Yiisoft\Data\Reader\Filter\All; diff --git a/tests/Reader/IterableHandler/AllTest.php b/tests/Reader/IterableHandler/AllTest.php index 2ff21ca3..32d71d2c 100644 --- a/tests/Reader/IterableHandler/AllTest.php +++ b/tests/Reader/IterableHandler/AllTest.php @@ -33,32 +33,32 @@ public static function matchDataProvider(): array [ true, [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ true, [new Equals('value', '45'), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ false, [new Equals('value', 44), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ false, [new Equals('value', 45), new GreaterThanOrEqual('value', 46), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ false, [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 44)], - $handlers + $handlers, ], [ false, [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 44)], - $handlers + $handlers, ], ]; } diff --git a/tests/Reader/IterableHandler/AnyTest.php b/tests/Reader/IterableHandler/AnyTest.php index 80ce4917..3940ab8c 100644 --- a/tests/Reader/IterableHandler/AnyTest.php +++ b/tests/Reader/IterableHandler/AnyTest.php @@ -7,7 +7,6 @@ use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; -use stdClass; use Yiisoft\Data\Reader\Filter\Any; use Yiisoft\Data\Reader\Filter\Equals; use Yiisoft\Data\Reader\Filter\EqualsEmpty; @@ -17,7 +16,6 @@ use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; -use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; use Yiisoft\Data\Tests\Support\CustomFilter\FilterWithoutHandler; use Yiisoft\Data\Tests\TestCase; @@ -34,32 +32,32 @@ public static function matchDataProvider(): array [ true, [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ true, [new Equals('value', '45'), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ true, [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ true, [new Equals('value', 45), new GreaterThanOrEqual('value', 46), new LessThanOrEqual('value', 45)], - $handlers + $handlers, ], [ true, [new Equals('value', 45), new GreaterThanOrEqual('value', 45), new LessThanOrEqual('value', 44)], - $handlers + $handlers, ], [ false, [new Equals('value', 44), new GreaterThanOrEqual('value', 46), new LessThanOrEqual('value', 44)], - $handlers + $handlers, ], ]; } diff --git a/tests/Reader/IterableHandler/EqualsNullTest.php b/tests/Reader/IterableHandler/EqualsNullTest.php index 059c6f01..faa0ae5d 100644 --- a/tests/Reader/IterableHandler/EqualsNullTest.php +++ b/tests/Reader/IterableHandler/EqualsNullTest.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\EqualsNull; -use Yiisoft\Data\Reader\Iterable\FilterHandler\AnyHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNullHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; diff --git a/tests/Reader/IterableHandler/EqualsTest.php b/tests/Reader/IterableHandler/EqualsTest.php index c172700e..20b6ea88 100644 --- a/tests/Reader/IterableHandler/EqualsTest.php +++ b/tests/Reader/IterableHandler/EqualsTest.php @@ -10,7 +10,6 @@ use Yiisoft\Data\Reader\Filter\Equals; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; -use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNullHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php index 921316be..a92163a4 100644 --- a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php @@ -9,7 +9,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; -use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/InTest.php b/tests/Reader/IterableHandler/InTest.php index 3a65c597..b21e4532 100644 --- a/tests/Reader/IterableHandler/InTest.php +++ b/tests/Reader/IterableHandler/InTest.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\In; -use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\InHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/LessThanOrEqualTest.php b/tests/Reader/IterableHandler/LessThanOrEqualTest.php index 8031a87a..b4290ccd 100644 --- a/tests/Reader/IterableHandler/LessThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/LessThanOrEqualTest.php @@ -9,7 +9,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; -use Yiisoft\Data\Reader\Iterable\FilterHandler\InHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/LessThanTest.php b/tests/Reader/IterableHandler/LessThanTest.php index 25c37578..07f8f378 100644 --- a/tests/Reader/IterableHandler/LessThanTest.php +++ b/tests/Reader/IterableHandler/LessThanTest.php @@ -10,7 +10,6 @@ use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\LessThan; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanHandler; -use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; final class LessThanTest extends TestCase diff --git a/tests/Reader/IterableHandler/LikeTest.php b/tests/Reader/IterableHandler/LikeTest.php index a3755204..c7d6dbdd 100644 --- a/tests/Reader/IterableHandler/LikeTest.php +++ b/tests/Reader/IterableHandler/LikeTest.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\Like; -use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/NotTest.php b/tests/Reader/IterableHandler/NotTest.php index 067622ea..aa865bb2 100644 --- a/tests/Reader/IterableHandler/NotTest.php +++ b/tests/Reader/IterableHandler/NotTest.php @@ -7,13 +7,11 @@ use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; -use stdClass; use Yiisoft\Data\Reader\Filter\Equals; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\Not; use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; -use Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler; use Yiisoft\Data\Reader\Iterable\FilterHandler\NotHandler; use Yiisoft\Data\Tests\Support\CustomFilter\FilterWithoutHandler; use Yiisoft\Data\Tests\TestCase; From b2bd61e57784eaa613de2090845c6915791560ae Mon Sep 17 00:00:00 2001 From: samdark Date: Sat, 24 Feb 2024 08:50:01 +0000 Subject: [PATCH 3/8] Apply Rector changes (CI) --- src/Reader/Filter/Compare.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Reader/Filter/Compare.php b/src/Reader/Filter/Compare.php index 5f193a29..43537fb7 100644 --- a/src/Reader/Filter/Compare.php +++ b/src/Reader/Filter/Compare.php @@ -13,17 +13,12 @@ */ abstract class Compare implements FilterInterface { - private bool|DateTimeInterface|float|int|string $value; - /** * @param string $field Name of the field to compare. * @param bool|DateTimeInterface|float|int|string $value Value to compare to. */ - public function __construct( - public readonly string $field, - bool|DateTimeInterface|float|int|string $value - ) { - $this->value = $value; + public function __construct(public readonly string $field, private bool|DateTimeInterface|float|int|string $value) + { } public function getValue(): float|DateTimeInterface|bool|int|string From 21eca45b14f7d00e22f0166312d884423065ed4b Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Feb 2024 11:51:38 +0300 Subject: [PATCH 4/8] fix --- src/Reader/Filter/Compare.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Reader/Filter/Compare.php b/src/Reader/Filter/Compare.php index 43537fb7..02cbcb6c 100644 --- a/src/Reader/Filter/Compare.php +++ b/src/Reader/Filter/Compare.php @@ -17,8 +17,10 @@ abstract class Compare implements FilterInterface * @param string $field Name of the field to compare. * @param bool|DateTimeInterface|float|int|string $value Value to compare to. */ - public function __construct(public readonly string $field, private bool|DateTimeInterface|float|int|string $value) - { + public function __construct( + public readonly string $field, + private bool|DateTimeInterface|float|int|string $value, + ) { } public function getValue(): float|DateTimeInterface|bool|int|string From bc684654fd9cf33d7a5c458f07161216e6f3f6f6 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Feb 2024 12:38:56 +0300 Subject: [PATCH 5/8] improve --- src/Reader/Iterable/FilterHandler/AllHandler.php | 5 +---- src/Reader/Iterable/FilterHandler/AnyHandler.php | 4 +--- src/Reader/Iterable/FilterHandler/BetweenHandler.php | 4 +--- .../Iterable/FilterHandler/EqualsEmptyHandler.php | 4 +--- src/Reader/Iterable/FilterHandler/EqualsHandler.php | 4 +--- .../Iterable/FilterHandler/EqualsNullHandler.php | 4 +--- .../Iterable/FilterHandler/GreaterThanHandler.php | 4 +--- .../FilterHandler/GreaterThanOrEqualHandler.php | 4 +--- src/Reader/Iterable/FilterHandler/InHandler.php | 4 +--- src/Reader/Iterable/FilterHandler/LessThanHandler.php | 4 +--- .../Iterable/FilterHandler/LessThanOrEqualHandler.php | 4 +--- src/Reader/Iterable/FilterHandler/LikeHandler.php | 4 +--- src/Reader/Iterable/FilterHandler/NotHandler.php | 4 +--- tests/Reader/IterableHandler/AllTest.php | 10 ---------- tests/Reader/IterableHandler/AnyTest.php | 10 ---------- tests/Reader/IterableHandler/BetweenTest.php | 10 ---------- tests/Reader/IterableHandler/EqualsEmptyTest.php | 10 ---------- tests/Reader/IterableHandler/EqualsNullTest.php | 10 ---------- tests/Reader/IterableHandler/EqualsTest.php | 10 ---------- .../Reader/IterableHandler/GreaterThanOrEqualTest.php | 10 ---------- tests/Reader/IterableHandler/GreaterThanTest.php | 10 ---------- tests/Reader/IterableHandler/InTest.php | 10 ---------- tests/Reader/IterableHandler/LessThanOrEqualTest.php | 10 ---------- tests/Reader/IterableHandler/LessThanTest.php | 10 ---------- tests/Reader/IterableHandler/LikeTest.php | 10 ---------- tests/Reader/IterableHandler/NotTest.php | 10 ---------- 26 files changed, 13 insertions(+), 170 deletions(-) diff --git a/src/Reader/Iterable/FilterHandler/AllHandler.php b/src/Reader/Iterable/FilterHandler/AllHandler.php index 811f2d71..453246f1 100644 --- a/src/Reader/Iterable/FilterHandler/AllHandler.php +++ b/src/Reader/Iterable/FilterHandler/AllHandler.php @@ -7,7 +7,6 @@ use InvalidArgumentException; use LogicException; use Yiisoft\Data\Reader\Filter\All; - use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; @@ -24,9 +23,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof All) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var All $filter */ foreach ($filter->getFilters() as $subFilter) { $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; diff --git a/src/Reader/Iterable/FilterHandler/AnyHandler.php b/src/Reader/Iterable/FilterHandler/AnyHandler.php index d69d363b..b7577863 100644 --- a/src/Reader/Iterable/FilterHandler/AnyHandler.php +++ b/src/Reader/Iterable/FilterHandler/AnyHandler.php @@ -23,9 +23,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof Any) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var Any $filter */ foreach ($filter->getFilters() as $subFilter) { $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; diff --git a/src/Reader/Iterable/FilterHandler/BetweenHandler.php b/src/Reader/Iterable/FilterHandler/BetweenHandler.php index eb7e5c89..6d042c32 100644 --- a/src/Reader/Iterable/FilterHandler/BetweenHandler.php +++ b/src/Reader/Iterable/FilterHandler/BetweenHandler.php @@ -24,9 +24,7 @@ public function getFilterClass(): string public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof Between) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var Between $filter */ $value = ArrayHelper::getValue($item, $filter->field); diff --git a/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php b/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php index 014dfc3c..84b245bd 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php @@ -22,9 +22,7 @@ public function getFilterClass(): string public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof EqualsEmpty) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var EqualsEmpty $filter */ $value = ArrayHelper::getValue($item, $filter->field); diff --git a/src/Reader/Iterable/FilterHandler/EqualsHandler.php b/src/Reader/Iterable/FilterHandler/EqualsHandler.php index a03df749..fa9a8284 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsHandler.php @@ -23,9 +23,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof Equals) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var Equals $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->getValue(); diff --git a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php index e32abdca..841d0bd2 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php @@ -22,9 +22,7 @@ public function getFilterClass(): string public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof EqualsNull) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var EqualsNull $filter */ return ArrayHelper::getValue($item, $filter->field) === null; } diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php index 2916c21a..0ff920c3 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php @@ -23,9 +23,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof GreaterThan) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var GreaterThan $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->getValue(); diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php index 77195dd2..8752643b 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php @@ -24,9 +24,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof GreaterThanOrEqual) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var GreaterThanOrEqual $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->getValue(); diff --git a/src/Reader/Iterable/FilterHandler/InHandler.php b/src/Reader/Iterable/FilterHandler/InHandler.php index 929ca48e..9d197107 100644 --- a/src/Reader/Iterable/FilterHandler/InHandler.php +++ b/src/Reader/Iterable/FilterHandler/InHandler.php @@ -24,9 +24,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof In) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var In $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->getValues(); diff --git a/src/Reader/Iterable/FilterHandler/LessThanHandler.php b/src/Reader/Iterable/FilterHandler/LessThanHandler.php index 5e89e646..0422b623 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanHandler.php @@ -23,9 +23,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof LessThan) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var LessThan $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->getValue(); diff --git a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php index 51fc3280..f02f6d55 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php @@ -24,9 +24,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof LessThanOrEqual) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var LessThanOrEqual $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->getValue(); diff --git a/src/Reader/Iterable/FilterHandler/LikeHandler.php b/src/Reader/Iterable/FilterHandler/LikeHandler.php index 3a5e732a..36c3394e 100644 --- a/src/Reader/Iterable/FilterHandler/LikeHandler.php +++ b/src/Reader/Iterable/FilterHandler/LikeHandler.php @@ -26,9 +26,7 @@ public function getFilterClass(): string public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof Like) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var Like $filter */ $itemValue = ArrayHelper::getValue($item, $filter->field); $argumentValue = $filter->value; diff --git a/src/Reader/Iterable/FilterHandler/NotHandler.php b/src/Reader/Iterable/FilterHandler/NotHandler.php index 1f97bae2..b945e62c 100644 --- a/src/Reader/Iterable/FilterHandler/NotHandler.php +++ b/src/Reader/Iterable/FilterHandler/NotHandler.php @@ -24,9 +24,7 @@ public function getFilterClass(): string public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool { - if (!$filter instanceof Not) { - throw new InvalidArgumentException('Incorrect filter.'); - } + /** @var Not $filter */ $filterHandler = $iterableFilterHandlers[$filter->filter::class] ?? null; if ($filterHandler === null) { diff --git a/tests/Reader/IterableHandler/AllTest.php b/tests/Reader/IterableHandler/AllTest.php index 32d71d2c..e18571b5 100644 --- a/tests/Reader/IterableHandler/AllTest.php +++ b/tests/Reader/IterableHandler/AllTest.php @@ -83,14 +83,4 @@ public function testMatchFailIfFilterOperatorIsNotSupported(): void (new AllHandler())->match(['id' => 1], new All(new FilterWithoutHandler()), []); } - - public function testInvalidFilter(): void - { - $handler = new AllHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/AnyTest.php b/tests/Reader/IterableHandler/AnyTest.php index 3940ab8c..885bd826 100644 --- a/tests/Reader/IterableHandler/AnyTest.php +++ b/tests/Reader/IterableHandler/AnyTest.php @@ -82,14 +82,4 @@ public function testMatchFailIfFilterOperatorIsNotSupported(): void (new AnyHandler())->match(['id' => 1], new Any(new FilterWithoutHandler()), []); } - - public function testInvalidFilter(): void - { - $handler = new AnyHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/BetweenTest.php b/tests/Reader/IterableHandler/BetweenTest.php index 1d4166df..ada73e25 100644 --- a/tests/Reader/IterableHandler/BetweenTest.php +++ b/tests/Reader/IterableHandler/BetweenTest.php @@ -84,14 +84,4 @@ public function testObjectWithGetters(): void $this->assertSame([3 => $car3, 4 => $car4, 5 => $car5], $result); } - - public function testInvalidFilter(): void - { - $handler = new BetweenHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/EqualsEmptyTest.php b/tests/Reader/IterableHandler/EqualsEmptyTest.php index 4486d413..e154baa5 100644 --- a/tests/Reader/IterableHandler/EqualsEmptyTest.php +++ b/tests/Reader/IterableHandler/EqualsEmptyTest.php @@ -33,14 +33,4 @@ public function testMatch(bool $expected, array $item): void { $this->assertSame($expected, (new EqualsEmptyHandler())->match($item, new EqualsEmpty('value'), [])); } - - public function testInvalidFilter(): void - { - $handler = new EqualsEmptyHandler(); - $filter = new EqualsNull('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/EqualsNullTest.php b/tests/Reader/IterableHandler/EqualsNullTest.php index faa0ae5d..72a15f70 100644 --- a/tests/Reader/IterableHandler/EqualsNullTest.php +++ b/tests/Reader/IterableHandler/EqualsNullTest.php @@ -55,14 +55,4 @@ public function testObjectWithGetters(): void $this->assertSame([3 => $car3, 5 => $car5], $result); } - - public function testInvalidFilter(): void - { - $handler = new EqualsNullHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/EqualsTest.php b/tests/Reader/IterableHandler/EqualsTest.php index 20b6ea88..5c53a7ee 100644 --- a/tests/Reader/IterableHandler/EqualsTest.php +++ b/tests/Reader/IterableHandler/EqualsTest.php @@ -81,14 +81,4 @@ public function testObjectWithGetters(): void $this->assertSame([1 => $car1, 3 => $car3], $result); } - - public function testInvalidFilter(): void - { - $handler = new EqualsHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php index a92163a4..55c41bfb 100644 --- a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php @@ -58,14 +58,4 @@ public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $va $this->assertSame($expected, $processor->match($item, new GreaterThanOrEqual('value', $value), [])); } - - public function testInvalidFilter(): void - { - $handler = new GreaterThanOrEqualHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/GreaterThanTest.php b/tests/Reader/IterableHandler/GreaterThanTest.php index 892af8de..55f4e0ea 100644 --- a/tests/Reader/IterableHandler/GreaterThanTest.php +++ b/tests/Reader/IterableHandler/GreaterThanTest.php @@ -58,14 +58,4 @@ public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $va $this->assertSame($expected, $handler->match($item, new GreaterThan('value', $value), [])); } - - public function testInvalidFilter(): void - { - $handler = new GreaterThanHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/InTest.php b/tests/Reader/IterableHandler/InTest.php index b21e4532..76a863c4 100644 --- a/tests/Reader/IterableHandler/InTest.php +++ b/tests/Reader/IterableHandler/InTest.php @@ -34,14 +34,4 @@ public function testMatch(bool $expected, array $value): void $this->assertSame($expected, $handler->match($item, new In('value', $value), [])); } - - public function testInvalidFilter(): void - { - $handler = new InHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/LessThanOrEqualTest.php b/tests/Reader/IterableHandler/LessThanOrEqualTest.php index b4290ccd..7e47ca65 100644 --- a/tests/Reader/IterableHandler/LessThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/LessThanOrEqualTest.php @@ -58,14 +58,4 @@ public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $va $this->assertSame($expected, $handler->match($item, new LessThanOrEqual('value', $value), [])); } - - public function testInvalidFilter(): void - { - $handler = new LessThanOrEqualHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/LessThanTest.php b/tests/Reader/IterableHandler/LessThanTest.php index 07f8f378..740a90bb 100644 --- a/tests/Reader/IterableHandler/LessThanTest.php +++ b/tests/Reader/IterableHandler/LessThanTest.php @@ -58,14 +58,4 @@ public function testMatchDateTimeInterface(bool $expected, DateTimeImmutable $va $this->assertSame($expected, $handler->match($item, new LessThan('value', $value), [])); } - - public function testInvalidFilter(): void - { - $handler = new LessThanHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/LikeTest.php b/tests/Reader/IterableHandler/LikeTest.php index c7d6dbdd..000cb177 100644 --- a/tests/Reader/IterableHandler/LikeTest.php +++ b/tests/Reader/IterableHandler/LikeTest.php @@ -34,14 +34,4 @@ public function testMatch(bool $expected, string $field, string $value): void $this->assertSame($expected, $processor->match($item, new Like($field, $value), [])); } - - public function testInvalidFilter(): void - { - $handler = new LikeHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } diff --git a/tests/Reader/IterableHandler/NotTest.php b/tests/Reader/IterableHandler/NotTest.php index aa865bb2..cdd19b56 100644 --- a/tests/Reader/IterableHandler/NotTest.php +++ b/tests/Reader/IterableHandler/NotTest.php @@ -48,14 +48,4 @@ public function testMatchFailIfFilterOperatorIsNotSupported(): void (new NotHandler())->match(['id' => 1], new Not(new FilterWithoutHandler()), []); } - - public function testInvalidFilter(): void - { - $handler = new NotHandler(); - $filter = new EqualsEmpty('test'); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Incorrect filter.'); - $handler->match([], $filter, []); - } } From eae8303589db0b434b2b7ec400d783dab689a64b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 24 Feb 2024 09:39:08 +0000 Subject: [PATCH 6/8] Apply fixes from StyleCI --- src/Reader/Iterable/FilterHandler/AllHandler.php | 1 - src/Reader/Iterable/FilterHandler/AnyHandler.php | 1 - src/Reader/Iterable/FilterHandler/BetweenHandler.php | 1 - src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php | 1 - src/Reader/Iterable/FilterHandler/EqualsHandler.php | 1 - src/Reader/Iterable/FilterHandler/EqualsNullHandler.php | 1 - src/Reader/Iterable/FilterHandler/GreaterThanHandler.php | 1 - src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php | 1 - src/Reader/Iterable/FilterHandler/InHandler.php | 1 - src/Reader/Iterable/FilterHandler/LessThanHandler.php | 1 - src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php | 1 - src/Reader/Iterable/FilterHandler/LikeHandler.php | 1 - src/Reader/Iterable/FilterHandler/NotHandler.php | 1 - tests/Reader/IterableHandler/AllTest.php | 2 -- tests/Reader/IterableHandler/AnyTest.php | 2 -- tests/Reader/IterableHandler/BetweenTest.php | 2 -- tests/Reader/IterableHandler/EqualsEmptyTest.php | 2 -- tests/Reader/IterableHandler/EqualsNullTest.php | 2 -- tests/Reader/IterableHandler/EqualsTest.php | 2 -- tests/Reader/IterableHandler/GreaterThanOrEqualTest.php | 2 -- tests/Reader/IterableHandler/GreaterThanTest.php | 2 -- tests/Reader/IterableHandler/InTest.php | 2 -- tests/Reader/IterableHandler/LessThanOrEqualTest.php | 2 -- tests/Reader/IterableHandler/LessThanTest.php | 2 -- tests/Reader/IterableHandler/LikeTest.php | 2 -- tests/Reader/IterableHandler/NotTest.php | 2 -- 26 files changed, 39 deletions(-) diff --git a/src/Reader/Iterable/FilterHandler/AllHandler.php b/src/Reader/Iterable/FilterHandler/AllHandler.php index 453246f1..ca6c3a5c 100644 --- a/src/Reader/Iterable/FilterHandler/AllHandler.php +++ b/src/Reader/Iterable/FilterHandler/AllHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use LogicException; use Yiisoft\Data\Reader\Filter\All; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/AnyHandler.php b/src/Reader/Iterable/FilterHandler/AnyHandler.php index b7577863..c26708dd 100644 --- a/src/Reader/Iterable/FilterHandler/AnyHandler.php +++ b/src/Reader/Iterable/FilterHandler/AnyHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use LogicException; use Yiisoft\Data\Reader\Filter\Any; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/BetweenHandler.php b/src/Reader/Iterable/FilterHandler/BetweenHandler.php index 6d042c32..4c23cf7d 100644 --- a/src/Reader/Iterable/FilterHandler/BetweenHandler.php +++ b/src/Reader/Iterable/FilterHandler/BetweenHandler.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Between; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php b/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php index 84b245bd..9366b13e 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsEmptyHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/EqualsHandler.php b/src/Reader/Iterable/FilterHandler/EqualsHandler.php index fa9a8284..6c3dbaab 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsHandler.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Equals; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php index 841d0bd2..9dc57adc 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\EqualsNull; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php index 0ff920c3..a3aec02b 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\GreaterThan; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php index 8752643b..81e5b192 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/InHandler.php b/src/Reader/Iterable/FilterHandler/InHandler.php index 9d197107..ccf3c21b 100644 --- a/src/Reader/Iterable/FilterHandler/InHandler.php +++ b/src/Reader/Iterable/FilterHandler/InHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\In; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/LessThanHandler.php b/src/Reader/Iterable/FilterHandler/LessThanHandler.php index 0422b623..5f0d4fe6 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanHandler.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\LessThan; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php index f02f6d55..cfb8d922 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php @@ -5,7 +5,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; use DateTimeInterface; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\FilterInterface; diff --git a/src/Reader/Iterable/FilterHandler/LikeHandler.php b/src/Reader/Iterable/FilterHandler/LikeHandler.php index 36c3394e..2139da1c 100644 --- a/src/Reader/Iterable/FilterHandler/LikeHandler.php +++ b/src/Reader/Iterable/FilterHandler/LikeHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Like; diff --git a/src/Reader/Iterable/FilterHandler/NotHandler.php b/src/Reader/Iterable/FilterHandler/NotHandler.php index b945e62c..a8b6cbf8 100644 --- a/src/Reader/Iterable/FilterHandler/NotHandler.php +++ b/src/Reader/Iterable/FilterHandler/NotHandler.php @@ -4,7 +4,6 @@ namespace Yiisoft\Data\Reader\Iterable\FilterHandler; -use InvalidArgumentException; use LogicException; use Yiisoft\Data\Reader\Filter\Not; use Yiisoft\Data\Reader\FilterInterface; diff --git a/tests/Reader/IterableHandler/AllTest.php b/tests/Reader/IterableHandler/AllTest.php index e18571b5..8f0fb654 100644 --- a/tests/Reader/IterableHandler/AllTest.php +++ b/tests/Reader/IterableHandler/AllTest.php @@ -4,12 +4,10 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\All; use Yiisoft\Data\Reader\Filter\Equals; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Iterable\FilterHandler\AllHandler; diff --git a/tests/Reader/IterableHandler/AnyTest.php b/tests/Reader/IterableHandler/AnyTest.php index 885bd826..f2b80fb4 100644 --- a/tests/Reader/IterableHandler/AnyTest.php +++ b/tests/Reader/IterableHandler/AnyTest.php @@ -4,12 +4,10 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\Any; use Yiisoft\Data\Reader\Filter\Equals; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Iterable\FilterHandler\AnyHandler; diff --git a/tests/Reader/IterableHandler/BetweenTest.php b/tests/Reader/IterableHandler/BetweenTest.php index ada73e25..850cb78f 100644 --- a/tests/Reader/IterableHandler/BetweenTest.php +++ b/tests/Reader/IterableHandler/BetweenTest.php @@ -5,10 +5,8 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use DateTimeImmutable; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\Between; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Iterable\FilterHandler\BetweenHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; diff --git a/tests/Reader/IterableHandler/EqualsEmptyTest.php b/tests/Reader/IterableHandler/EqualsEmptyTest.php index e154baa5..4a157b74 100644 --- a/tests/Reader/IterableHandler/EqualsEmptyTest.php +++ b/tests/Reader/IterableHandler/EqualsEmptyTest.php @@ -4,10 +4,8 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\EqualsEmpty; -use Yiisoft\Data\Reader\Filter\EqualsNull; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsEmptyHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/EqualsNullTest.php b/tests/Reader/IterableHandler/EqualsNullTest.php index 72a15f70..607aaf9d 100644 --- a/tests/Reader/IterableHandler/EqualsNullTest.php +++ b/tests/Reader/IterableHandler/EqualsNullTest.php @@ -4,9 +4,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\EqualsNull; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNullHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; diff --git a/tests/Reader/IterableHandler/EqualsTest.php b/tests/Reader/IterableHandler/EqualsTest.php index 5c53a7ee..23faa915 100644 --- a/tests/Reader/IterableHandler/EqualsTest.php +++ b/tests/Reader/IterableHandler/EqualsTest.php @@ -5,10 +5,8 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use DateTimeImmutable; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\Equals; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; use Yiisoft\Data\Reader\Iterable\IterableDataReader; use Yiisoft\Data\Tests\Support\Car; diff --git a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php index 55c41bfb..4336feda 100644 --- a/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/GreaterThanOrEqualTest.php @@ -5,9 +5,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use DateTimeImmutable; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\GreaterThanOrEqual; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/GreaterThanTest.php b/tests/Reader/IterableHandler/GreaterThanTest.php index 55f4e0ea..62c1914b 100644 --- a/tests/Reader/IterableHandler/GreaterThanTest.php +++ b/tests/Reader/IterableHandler/GreaterThanTest.php @@ -5,9 +5,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use DateTimeImmutable; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\GreaterThan; use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/InTest.php b/tests/Reader/IterableHandler/InTest.php index 76a863c4..126fe5b2 100644 --- a/tests/Reader/IterableHandler/InTest.php +++ b/tests/Reader/IterableHandler/InTest.php @@ -4,9 +4,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\In; use Yiisoft\Data\Reader\Iterable\FilterHandler\InHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/LessThanOrEqualTest.php b/tests/Reader/IterableHandler/LessThanOrEqualTest.php index 7e47ca65..3c05c75b 100644 --- a/tests/Reader/IterableHandler/LessThanOrEqualTest.php +++ b/tests/Reader/IterableHandler/LessThanOrEqualTest.php @@ -5,9 +5,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use DateTimeImmutable; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\LessThanOrEqual; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/LessThanTest.php b/tests/Reader/IterableHandler/LessThanTest.php index 740a90bb..7b5a51c1 100644 --- a/tests/Reader/IterableHandler/LessThanTest.php +++ b/tests/Reader/IterableHandler/LessThanTest.php @@ -5,9 +5,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; use DateTimeImmutable; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\LessThan; use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/LikeTest.php b/tests/Reader/IterableHandler/LikeTest.php index 000cb177..f5a943f6 100644 --- a/tests/Reader/IterableHandler/LikeTest.php +++ b/tests/Reader/IterableHandler/LikeTest.php @@ -4,9 +4,7 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\Like; use Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler; use Yiisoft\Data\Tests\TestCase; diff --git a/tests/Reader/IterableHandler/NotTest.php b/tests/Reader/IterableHandler/NotTest.php index cdd19b56..62ac72e5 100644 --- a/tests/Reader/IterableHandler/NotTest.php +++ b/tests/Reader/IterableHandler/NotTest.php @@ -4,11 +4,9 @@ namespace Yiisoft\Data\Tests\Reader\IterableHandler; -use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Data\Reader\Filter\Equals; -use Yiisoft\Data\Reader\Filter\EqualsEmpty; use Yiisoft\Data\Reader\Filter\Not; use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler; From 5ee6255058540d92028380e80dfe08c0584e6ad5 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 25 Feb 2024 18:09:50 +0300 Subject: [PATCH 7/8] improve --- src/Reader/Filter/All.php | 18 +++++++--------- src/Reader/Filter/Any.php | 17 +++++++-------- src/Reader/Filter/Between.php | 21 ++++++++++++++++--- src/Reader/Filter/Compare.php | 8 +++++-- src/Reader/Filter/EqualsNull.php | 7 ++++++- src/Reader/Filter/GreaterThan.php | 3 +-- src/Reader/Filter/GreaterThanOrEqual.php | 3 +-- src/Reader/Filter/Group.php | 2 +- src/Reader/Filter/In.php | 7 ++++++- src/Reader/Filter/Like.php | 14 +++++++++++-- src/Reader/Filter/Not.php | 7 ++++++- .../Iterable/FilterHandler/BetweenHandler.php | 14 +++++++------ .../Iterable/FilterHandler/EqualsHandler.php | 2 +- .../FilterHandler/EqualsNullHandler.php | 2 +- .../FilterHandler/GreaterThanHandler.php | 2 +- .../GreaterThanOrEqualHandler.php | 2 +- .../Iterable/FilterHandler/InHandler.php | 2 +- .../FilterHandler/LessThanHandler.php | 2 +- .../FilterHandler/LessThanOrEqualHandler.php | 2 +- .../Iterable/FilterHandler/LikeHandler.php | 5 ++--- .../Iterable/FilterHandler/NotHandler.php | 8 ++++--- tests/Reader/IterableDataReaderTest.php | 2 +- 22 files changed, 95 insertions(+), 55 deletions(-) diff --git a/src/Reader/Filter/All.php b/src/Reader/Filter/All.php index 5121f108..0e971d4a 100644 --- a/src/Reader/Filter/All.php +++ b/src/Reader/Filter/All.php @@ -5,18 +5,16 @@ namespace Yiisoft\Data\Reader\Filter; /** - * `All` filter allows combining multiple criteria or sub-filters using "and" operator. + * `All` filter allows combining multiple sub-filters using "and" operator. * * ```php - * $dataReader->withFilter((new All())->withCriteriaArray( - * [ - * ['>', 'id', 88], - * ['and', [ - * ['=', 'state', 2], - * ['like', 'name', 'eva'], - * ], - * ] - * )); + * $dataReader->withFilter( + * new All( + * new GreaterThan('id', 88), + * new Equals('state', 2), + * new Like('name', 'eva'), + * ) + * ); * ``` */ final class All extends Group diff --git a/src/Reader/Filter/Any.php b/src/Reader/Filter/Any.php index 7b931e03..08a92a41 100644 --- a/src/Reader/Filter/Any.php +++ b/src/Reader/Filter/Any.php @@ -5,18 +5,15 @@ namespace Yiisoft\Data\Reader\Filter; /** - * `Any` filter allows combining multiple criteria or sub-filters using "or" operator. + * `Any` filter allows combining multiple sub-filters using "or" operator. * * ```php - * $dataReader->withFilter((new Any())->withCriteriaArray( - * [ - * ['>', 'id', 88], - * ['or', [ - * ['=', 'state', 2], - * ['like', 'name', 'eva'], - * ], - * ] - * )); + * $dataReader->withFilter( + * new Any( + * new GreaterThan('id', 88), + * new Equals('state', 2), + * ) + * ); * ``` */ final class Any extends Group diff --git a/src/Reader/Filter/Between.php b/src/Reader/Filter/Between.php index de305923..5128c3b3 100644 --- a/src/Reader/Filter/Between.php +++ b/src/Reader/Filter/Between.php @@ -19,9 +19,24 @@ final class Between implements FilterInterface * @param bool|DateTimeInterface|float|int|string $maxValue Maximal field value. */ public function __construct( - public readonly string $field, - public readonly bool|DateTimeInterface|float|int|string $minValue, - public readonly bool|DateTimeInterface|float|int|string $maxValue + private readonly string $field, + private readonly bool|DateTimeInterface|float|int|string $minValue, + private readonly bool|DateTimeInterface|float|int|string $maxValue ) { } + + public function getField(): string + { + return $this->field; + } + + public function getMinValue(): float|DateTimeInterface|bool|int|string + { + return $this->minValue; + } + + public function getMaxValue(): float|DateTimeInterface|bool|int|string + { + return $this->maxValue; + } } diff --git a/src/Reader/Filter/Compare.php b/src/Reader/Filter/Compare.php index 02cbcb6c..546da999 100644 --- a/src/Reader/Filter/Compare.php +++ b/src/Reader/Filter/Compare.php @@ -9,7 +9,6 @@ /** * `Compare` filter is a base class that defines a criteria for comparing field value with a given value. - * The operator is defined by child classes. */ abstract class Compare implements FilterInterface { @@ -18,11 +17,16 @@ abstract class Compare implements FilterInterface * @param bool|DateTimeInterface|float|int|string $value Value to compare to. */ public function __construct( - public readonly string $field, + private readonly string $field, private bool|DateTimeInterface|float|int|string $value, ) { } + public function getField(): string + { + return $this->field; + } + public function getValue(): float|DateTimeInterface|bool|int|string { return $this->value; diff --git a/src/Reader/Filter/EqualsNull.php b/src/Reader/Filter/EqualsNull.php index d3d354e4..9a48c4c1 100644 --- a/src/Reader/Filter/EqualsNull.php +++ b/src/Reader/Filter/EqualsNull.php @@ -15,7 +15,12 @@ final class EqualsNull implements FilterInterface * @param string $field Name of the field to check. */ public function __construct( - public readonly string $field + private readonly string $field, ) { } + + public function getField(): string + { + return $this->field; + } } diff --git a/src/Reader/Filter/GreaterThan.php b/src/Reader/Filter/GreaterThan.php index 5ac460e0..ec474b6d 100644 --- a/src/Reader/Filter/GreaterThan.php +++ b/src/Reader/Filter/GreaterThan.php @@ -5,8 +5,7 @@ namespace Yiisoft\Data\Reader\Filter; /** - * `GreaterThan` filter defines a criteria for ensuring field value - * is greater than a given value. + * `GreaterThan` filter defines a criteria for ensuring field value is greater than a given value. */ final class GreaterThan extends Compare { diff --git a/src/Reader/Filter/GreaterThanOrEqual.php b/src/Reader/Filter/GreaterThanOrEqual.php index 14aad92c..feb95371 100644 --- a/src/Reader/Filter/GreaterThanOrEqual.php +++ b/src/Reader/Filter/GreaterThanOrEqual.php @@ -5,8 +5,7 @@ namespace Yiisoft\Data\Reader\Filter; /** - * `GreaterThanOrEqual` filter defines a criteria for ensuring field value - * is greater than or equal to a given value. + * `GreaterThanOrEqual` filter defines a criteria for ensuring field value is greater than or equal to a given value. */ final class GreaterThanOrEqual extends Compare { diff --git a/src/Reader/Filter/Group.php b/src/Reader/Filter/Group.php index 8170f22f..903ee18c 100644 --- a/src/Reader/Filter/Group.php +++ b/src/Reader/Filter/Group.php @@ -7,7 +7,7 @@ use Yiisoft\Data\Reader\FilterInterface; /** - * `Group` filter is an abstract class that allows combining multiple criteria or sub-filters. + * `Group` filter is an abstract class that allows combining multiple sub-filters. */ abstract class Group implements FilterInterface { diff --git a/src/Reader/Filter/In.php b/src/Reader/Filter/In.php index e14be733..525b70ff 100644 --- a/src/Reader/Filter/In.php +++ b/src/Reader/Filter/In.php @@ -22,7 +22,7 @@ final class In implements FilterInterface * @param bool[]|float[]|int[]|string[] $values Values to check against. */ public function __construct( - public readonly string $field, + private readonly string $field, array $values ) { foreach ($values as $value) { @@ -39,6 +39,11 @@ public function __construct( $this->values = $values; } + public function getField(): string + { + return $this->field; + } + /** * @return bool[]|float[]|int[]|string[] */ diff --git a/src/Reader/Filter/Like.php b/src/Reader/Filter/Like.php index ac7e36d7..fc6781f1 100644 --- a/src/Reader/Filter/Like.php +++ b/src/Reader/Filter/Like.php @@ -16,8 +16,18 @@ final class Like implements FilterInterface * @param string $value Value to like-compare with. */ public function __construct( - public readonly string $field, - public readonly string $value, + private readonly string $field, + private readonly string $value, ) { } + + public function getField(): string + { + return $this->field; + } + + public function getValue(): string + { + return $this->value; + } } diff --git a/src/Reader/Filter/Not.php b/src/Reader/Filter/Not.php index 35dba8f2..a7de17b1 100644 --- a/src/Reader/Filter/Not.php +++ b/src/Reader/Filter/Not.php @@ -15,7 +15,12 @@ final class Not implements FilterInterface * @param FilterInterface $filter Filter to negate. */ public function __construct( - public readonly FilterInterface $filter + private readonly FilterInterface $filter, ) { } + + public function getFilter(): FilterInterface + { + return $this->filter; + } } diff --git a/src/Reader/Iterable/FilterHandler/BetweenHandler.php b/src/Reader/Iterable/FilterHandler/BetweenHandler.php index 4c23cf7d..5d87b94b 100644 --- a/src/Reader/Iterable/FilterHandler/BetweenHandler.php +++ b/src/Reader/Iterable/FilterHandler/BetweenHandler.php @@ -25,15 +25,17 @@ public function match(array|object $item, FilterInterface $filter, array $iterab { /** @var Between $filter */ - $value = ArrayHelper::getValue($item, $filter->field); + $value = ArrayHelper::getValue($item, $filter->getField()); + $min = $filter->getMinValue(); + $max = $filter->getMaxValue(); if (!$value instanceof DateTimeInterface) { - return $value >= $filter->minValue && $value <= $filter->maxValue; + return $value >= $min && $value <= $max; } - return $filter->minValue instanceof DateTimeInterface - && $filter->maxValue instanceof DateTimeInterface - && $value->getTimestamp() >= $filter->minValue->getTimestamp() - && $value->getTimestamp() <= $filter->maxValue->getTimestamp(); + return $min instanceof DateTimeInterface + && $max instanceof DateTimeInterface + && $value->getTimestamp() >= $min->getTimestamp() + && $value->getTimestamp() <= $max->getTimestamp(); } } diff --git a/src/Reader/Iterable/FilterHandler/EqualsHandler.php b/src/Reader/Iterable/FilterHandler/EqualsHandler.php index 6c3dbaab..3a2f7dee 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsHandler.php @@ -24,7 +24,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var Equals $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); + $itemValue = ArrayHelper::getValue($item, $filter->getField()); $argumentValue = $filter->getValue(); if (!$itemValue instanceof DateTimeInterface) { diff --git a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php index 9dc57adc..72a82d1c 100644 --- a/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php +++ b/src/Reader/Iterable/FilterHandler/EqualsNullHandler.php @@ -23,6 +23,6 @@ public function match(array|object $item, FilterInterface $filter, array $iterab { /** @var EqualsNull $filter */ - return ArrayHelper::getValue($item, $filter->field) === null; + return ArrayHelper::getValue($item, $filter->getField()) === null; } } diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php index a3aec02b..72e36f85 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanHandler.php @@ -24,7 +24,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var GreaterThan $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); + $itemValue = ArrayHelper::getValue($item, $filter->getField()); $argumentValue = $filter->getValue(); if (!$itemValue instanceof DateTimeInterface) { diff --git a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php index 81e5b192..5e37b581 100644 --- a/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/GreaterThanOrEqualHandler.php @@ -25,7 +25,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var GreaterThanOrEqual $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); + $itemValue = ArrayHelper::getValue($item, $filter->getField()); $argumentValue = $filter->getValue(); if (!$itemValue instanceof DateTimeInterface) { diff --git a/src/Reader/Iterable/FilterHandler/InHandler.php b/src/Reader/Iterable/FilterHandler/InHandler.php index ccf3c21b..48a6f47c 100644 --- a/src/Reader/Iterable/FilterHandler/InHandler.php +++ b/src/Reader/Iterable/FilterHandler/InHandler.php @@ -25,7 +25,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var In $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); + $itemValue = ArrayHelper::getValue($item, $filter->getField()); $argumentValue = $filter->getValues(); return in_array($itemValue, $argumentValue); diff --git a/src/Reader/Iterable/FilterHandler/LessThanHandler.php b/src/Reader/Iterable/FilterHandler/LessThanHandler.php index 5f0d4fe6..b48d41c3 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanHandler.php @@ -24,7 +24,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var LessThan $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); + $itemValue = ArrayHelper::getValue($item, $filter->getField()); $argumentValue = $filter->getValue(); if (!$itemValue instanceof DateTimeInterface) { diff --git a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php index cfb8d922..14047393 100644 --- a/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php +++ b/src/Reader/Iterable/FilterHandler/LessThanOrEqualHandler.php @@ -25,7 +25,7 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var LessThanOrEqual $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); + $itemValue = ArrayHelper::getValue($item, $filter->getField()); $argumentValue = $filter->getValue(); if (!$itemValue instanceof DateTimeInterface) { diff --git a/src/Reader/Iterable/FilterHandler/LikeHandler.php b/src/Reader/Iterable/FilterHandler/LikeHandler.php index 2139da1c..a4faa666 100644 --- a/src/Reader/Iterable/FilterHandler/LikeHandler.php +++ b/src/Reader/Iterable/FilterHandler/LikeHandler.php @@ -27,9 +27,8 @@ public function match(object|array $item, FilterInterface $filter, array $iterab { /** @var Like $filter */ - $itemValue = ArrayHelper::getValue($item, $filter->field); - $argumentValue = $filter->value; + $itemValue = ArrayHelper::getValue($item, $filter->getField()); - return is_string($itemValue) && stripos($itemValue, $argumentValue) !== false; + return is_string($itemValue) && stripos($itemValue, $filter->getValue()) !== false; } } diff --git a/src/Reader/Iterable/FilterHandler/NotHandler.php b/src/Reader/Iterable/FilterHandler/NotHandler.php index a8b6cbf8..3eaa6025 100644 --- a/src/Reader/Iterable/FilterHandler/NotHandler.php +++ b/src/Reader/Iterable/FilterHandler/NotHandler.php @@ -25,10 +25,12 @@ public function match(array|object $item, FilterInterface $filter, array $iterab { /** @var Not $filter */ - $filterHandler = $iterableFilterHandlers[$filter->filter::class] ?? null; + $subFilter = $filter->getFilter(); + + $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null; if ($filterHandler === null) { - throw new LogicException(sprintf('Filter "%s" is not supported.', $filter->filter::class)); + throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class)); } - return !$filterHandler->match($item, $filter->filter, $iterableFilterHandlers); + return !$filterHandler->match($item, $subFilter, $iterableFilterHandlers); } } diff --git a/tests/Reader/IterableDataReaderTest.php b/tests/Reader/IterableDataReaderTest.php index a3ca63e2..74069b37 100644 --- a/tests/Reader/IterableDataReaderTest.php +++ b/tests/Reader/IterableDataReaderTest.php @@ -411,7 +411,7 @@ public function match( array $iterableFilterHandlers ): bool { /** @var Equals $filter */ - return $item[$filter->field] === 2; + return $item[$filter->getField()] === 2; } } ); From 805cbec22a69d6076c50206b31e993f7cb7bf3e7 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 25 Feb 2024 18:17:40 +0300 Subject: [PATCH 8/8] fix --- src/Reader/Iterable/FilterHandler/LikeHandler.php | 1 - tests/Reader/Filter/InTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Reader/Iterable/FilterHandler/LikeHandler.php b/src/Reader/Iterable/FilterHandler/LikeHandler.php index a4faa666..5dac7d36 100644 --- a/src/Reader/Iterable/FilterHandler/LikeHandler.php +++ b/src/Reader/Iterable/FilterHandler/LikeHandler.php @@ -6,7 +6,6 @@ use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Data\Reader\Filter\Like; - use Yiisoft\Data\Reader\FilterInterface; use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface; diff --git a/tests/Reader/Filter/InTest.php b/tests/Reader/Filter/InTest.php index cce0a6a7..555e4ce2 100644 --- a/tests/Reader/Filter/InTest.php +++ b/tests/Reader/Filter/InTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Reader\Filter; +namespace Yiisoft\Data\Tests\Reader\Filter; use InvalidArgumentException; use stdClass;