Skip to content

Commit

Permalink
Add Handler suffix to filter handlers (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Jan 11, 2023
1 parent cc7bc93 commit 273064b
Show file tree
Hide file tree
Showing 30 changed files with 142 additions and 142 deletions.
Expand Up @@ -10,7 +10,7 @@
* `All` iterable filter handler allows combining multiple sub-filters.
* The filter matches only if all the sub-filters match.
*/
final class All extends Group
final class AllHandler extends GroupHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -10,7 +10,7 @@
* `Any` iterable filter handler allows combining multiple sub-filters.
* The filter matches if any of the sub-filters match.
*/
final class Any extends Group
final class AnyHandler extends GroupHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -16,7 +16,7 @@
* `Between` iterable filter handler checks that the item's field value
* is between minimal and maximal values.
*/
final class Between implements IterableFilterHandlerInterface
final class BetweenHandler implements IterableFilterHandlerInterface
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -15,7 +15,7 @@
* Abstract `Compare` iterable filter handler compares item's field value with a given value.
* The actual comparison is defined in {@see compare()} method implemented in child classes.
*/
abstract class Compare implements IterableFilterHandlerInterface
abstract class CompareHandler implements IterableFilterHandlerInterface
{
/**
* Compare item's field value with a given value.
Expand Down
Expand Up @@ -13,7 +13,7 @@
/**
* `EqualsEmpty` iterable filter handler checks that the item's field value is empty.
*/
final class EqualsEmpty implements IterableFilterHandlerInterface
final class EqualsEmptyHandler implements IterableFilterHandlerInterface
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -9,7 +9,7 @@
/**
* `Equals` iterable filter handler checks that the item's field value matches given value.
*/
final class Equals extends Compare
final class EqualsHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -14,7 +14,7 @@
/**
* `EqualsNull` iterable filter handler checks that the item's field value is null.
*/
final class EqualsNull implements IterableFilterHandlerInterface
final class EqualsNullHandler implements IterableFilterHandlerInterface
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -9,7 +9,7 @@
/**
* `GreaterThan` iterable filter handler checks that the item's field value is greater than the given value.
*/
final class GreaterThan extends Compare
final class GreaterThanHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -10,7 +10,7 @@
* `GreaterThanOrEqual` iterable filter handler checks that the item's field value
* is greater than or equal to the given value.
*/
final class GreaterThanOrEqual extends Compare
final class GreaterThanOrEqualHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -19,7 +19,7 @@
* How to interpret results is determined by {@see checkResults()} implemented in child
* classes.
*/
abstract class Group implements IterableFilterHandlerInterface
abstract class GroupHandler implements IterableFilterHandlerInterface
{
/**
* Return final decision for the match based on sub-filter match results.
Expand Down
Expand Up @@ -10,7 +10,7 @@
/**
* `In` iterable filter handler ensures that the field value matches one of the value provided.
*/
final class In extends Compare
final class InHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -9,7 +9,7 @@
/**
* `LessThan` iterable filter handler checks that the item's field value is less than the given value.
*/
final class LessThan extends Compare
final class LessThanHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -10,7 +10,7 @@
* `LessThanOrEqual` iterable filter handler checks that the item's field value
* is less than or equal to the given value.
*/
final class LessThanOrEqual extends Compare
final class LessThanOrEqualHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -10,7 +10,7 @@
/**
* `Like` iterable filter handler ensures that the field value is like-match to a given value.
*/
final class Like extends Compare
final class LikeHandler extends CompareHandler
{
public function getOperator(): string
{
Expand Down
Expand Up @@ -17,7 +17,7 @@
/**
* `Not` iterable filter handler negates another filter.
*/
final class Not implements IterableFilterHandlerInterface
final class NotHandler implements IterableFilterHandlerInterface
{
public function getOperator(): string
{
Expand Down
52 changes: 26 additions & 26 deletions src/Reader/Iterable/IterableDataReader.php
Expand Up @@ -13,19 +13,19 @@
use Yiisoft\Data\Reader\DataReaderInterface;
use Yiisoft\Data\Reader\FilterHandlerInterface;
use Yiisoft\Data\Reader\FilterInterface;
use Yiisoft\Data\Reader\Iterable\FilterHandler\All;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Any;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Between;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Equals;
use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsEmpty;
use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNull;
use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThan;
use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqual;
use Yiisoft\Data\Reader\Iterable\FilterHandler\In;
use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThan;
use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqual;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Like;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Not;
use Yiisoft\Data\Reader\Iterable\FilterHandler\AllHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\AnyHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\BetweenHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsEmptyHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\EqualsNullHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqualHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\InHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\LessThanOrEqualHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler;
use Yiisoft\Data\Reader\Iterable\FilterHandler\NotHandler;
use Yiisoft\Data\Reader\Sort;

use function array_merge;
Expand Down Expand Up @@ -69,19 +69,19 @@ class IterableDataReader implements DataReaderInterface
public function __construct(protected iterable $data)
{
$this->iterableFilterHandlers = $this->withFilterHandlers(
new All(),
new Any(),
new Between(),
new Equals(),
new EqualsEmpty(),
new EqualsNull(),
new GreaterThan(),
new GreaterThanOrEqual(),
new In(),
new LessThan(),
new LessThanOrEqual(),
new Like(),
new Not()
new AllHandler(),
new AnyHandler(),
new BetweenHandler(),
new EqualsHandler(),
new EqualsEmptyHandler(),
new EqualsNullHandler(),
new GreaterThanHandler(),
new GreaterThanOrEqualHandler(),
new InHandler(),
new LessThanHandler(),
new LessThanOrEqualHandler(),
new LikeHandler(),
new NotHandler()
)->iterableFilterHandlers;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Reader/IterableDataReaderTest.php
Expand Up @@ -23,7 +23,7 @@
use Yiisoft\Data\Reader\FilterAssert;
use Yiisoft\Data\Reader\FilterHandlerInterface;
use Yiisoft\Data\Reader\FilterInterface;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Compare;
use Yiisoft\Data\Reader\Iterable\FilterHandler\CompareHandler;
use Yiisoft\Data\Reader\Iterable\IterableDataReader;
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
use Yiisoft\Data\Reader\Sort;
Expand Down Expand Up @@ -424,7 +424,7 @@ public function testCustomEqualsProcessor(): void

$dataReader = (new IterableDataReader(self::DEFAULT_DATASET))
->withSort($sort)
->withFilterHandlers(new class () extends Compare {
->withFilterHandlers(new class () extends CompareHandler {
public function getOperator(): string
{
return Equals::getOperator();
Expand Down
38 changes: 19 additions & 19 deletions tests/Reader/IterableHandler/AllTest.php
Expand Up @@ -6,10 +6,10 @@

use InvalidArgumentException;
use stdClass;
use Yiisoft\Data\Reader\Iterable\FilterHandler\All;
use Yiisoft\Data\Reader\Iterable\FilterHandler\Equals;
use Yiisoft\Data\Reader\Iterable\FilterHandler\GreaterThanOrEqual;
use Yiisoft\Data\Reader\Iterable\FilterHandler\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\TestCase;

Expand All @@ -21,32 +21,32 @@ public function matchDataProvider(): array
[
true,
[[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 45]]],
['=' => new Equals(), '>=' => new GreaterThanOrEqual(), '<=' => new LessThanOrEqual()],
['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()],
],
[
true,
[[['=', 'value', '45'], ['>=', 'value', 45], ['<=', 'value', 45]]],
['=' => new Equals(), '>=' => new GreaterThanOrEqual(), '<=' => new LessThanOrEqual()],
['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()],
],
[
false,
[[['=', 'value', 44], ['>=', 'value', 45], ['<=', 'value', 45]]],
['=' => new Equals(), '>=' => new GreaterThanOrEqual(), '<=' => new LessThanOrEqual()],
['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()],
],
[
false,
[[['=', 'value', 45], ['>=', 'value', 46], ['<=', 'value', 45]]],
['=' => new Equals(), '>=' => new GreaterThanOrEqual(), '<=' => new LessThanOrEqual()],
['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()],
],
[
false,
[[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 44]]],
['=' => new Equals(), '>=' => new GreaterThanOrEqual(), '<=' => new LessThanOrEqual()],
['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()],
],
[
false,
[[['=', 'value', 45], ['>=', 'value', 45], ['<=', 'value', 44]]],
['=' => new Equals(), '>=' => new GreaterThanOrEqual(), '<=' => new LessThanOrEqual()],
['=' => new EqualsHandler(), '>=' => new GreaterThanOrEqualHandler(), '<=' => new LessThanOrEqualHandler()],
],
];
}
Expand All @@ -56,7 +56,7 @@ public function matchDataProvider(): array
*/
public function testMatch(bool $expected, array $arguments, array $filterHandlers): void
{
$processor = new All();
$processor = new AllHandler();

$item = [
'id' => 1,
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testMatchFailForInvalidCountArguments($arguments): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$arguments should contain exactly one element.');

(new All())->match(['id' => 1], $arguments, []);
(new AllHandler())->match(['id' => 1], $arguments, []);
}

/**
Expand All @@ -97,7 +97,7 @@ public function testMatchFailIfSubFiltersIsNotArray($subFilters): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("The sub filters should be array. The $type is received.");

(new All())->match(['id' => 1], [$subFilters], []);
(new AllHandler())->match(['id' => 1], [$subFilters], []);
}

/**
Expand All @@ -110,15 +110,15 @@ public function testMatchFailIfSubFilterIsNotArray($subFilters): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("The sub filter should be array. The $type is received.");

(new All())->match(['id' => 1], [[$subFilters]], []);
(new AllHandler())->match(['id' => 1], [[$subFilters]], []);
}

public function testMatchFailIfArgumentValueIsEmptyArray(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At least operator should be provided.');

(new All())->match(['id' => 1], [[[]]], []);
(new AllHandler())->match(['id' => 1], [[[]]], []);
}

public function invalidFilterOperatorDataProvider(): array
Expand All @@ -138,23 +138,23 @@ public function testMatchFailForInvalidFilterOperator(array $filter): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("The operator should be string. The $type is received.");

(new All())->match(['id' => 1], [[$filter]], []);
(new AllHandler())->match(['id' => 1], [[$filter]], []);
}

public function testMatchFailForEmptyFilterOperator(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The operator string cannot be empty.');

(new All())->match(['id' => 1], [[['']]], []);
(new AllHandler())->match(['id' => 1], [[['']]], []);
}

public function testMatchFailIfFilterOperatorIsNotSupported(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('">" operator is not supported.');

(new All())->match(['id' => 1], [[['>']]], ['=' => new Equals()]);
(new AllHandler())->match(['id' => 1], [[['>']]], ['=' => new EqualsHandler()]);
}

public function testMatchFailIfFilterHandlerIsNotIterable(): void
Expand All @@ -166,6 +166,6 @@ public function testMatchFailIfFilterHandlerIsNotIterable(): void
stdClass::class,
));

(new All())->match(['id' => 1], [[['=']]], ['=' => new stdClass()]);
(new AllHandler())->match(['id' => 1], [[['=']]], ['=' => new stdClass()]);
}
}

0 comments on commit 273064b

Please sign in to comment.