From 23a848b137f5aa524c611d34413940f40fd4c16b Mon Sep 17 00:00:00 2001 From: TemKaa1337 Date: Fri, 16 Aug 2024 17:02:31 +0300 Subject: [PATCH] Fix: rename ComparisonOperator values --- CHANGELOD.md | 5 +++++ README.md | 5 +---- src/Enum/ComparisonOperator.php | 8 ++++---- src/Processor/Condition/CompareProcessor.php | 18 +++++++++--------- tests/Unit/AbstractCollectionTestCase.php | 16 ++++++++-------- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CHANGELOD.md b/CHANGELOD.md index 955ae3e..e1288d5 100644 --- a/CHANGELOD.md +++ b/CHANGELOD.md @@ -1,3 +1,8 @@ +### 0.0.5 +##### Fixes: +- Renamed `Greater`, `GreaterOrEqual`, `Less` and `LessOrEqual` to `GreaterThan`, `GreaterThanOrEqual`, `LessThan` +and `LessOrEqual` respectively. + ### 0.0.4 ##### Features: - Added infection to project. diff --git a/README.md b/README.md index ecdf712..ff9c743 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ Simple Collections === -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/) -[![License](http://poser.pugx.org/temkaa/simple-collections/license)](https://packagist.org/packages/temkaa/simple-collections) -[![Total Downloads](http://poser.pugx.org/temkaa/simple-collections/downloads)](https://packagist.org/packages/temkaa/simple-collections) # This project offers a collection that provide convenient methods to manipulate your data. @@ -36,7 +33,7 @@ class SomeClass var_dump( (new Collection($products))->sort(new ByField('name', SortOrder::Desc))->toArray(), (new Collection($products)) - ->where(new Compare(field: 'name', operator: ComparisonOperator::Greater, value: 2)) + ->where(new Compare(field: 'name', operator: ComparisonOperator::GreaterThan, value: 2)) ->toArray(), (new Collection($products))->where(new Exactly(field: 'id', value: 1))->toArray(), ); diff --git a/src/Enum/ComparisonOperator.php b/src/Enum/ComparisonOperator.php index 9f2f00c..8718881 100644 --- a/src/Enum/ComparisonOperator.php +++ b/src/Enum/ComparisonOperator.php @@ -7,11 +7,11 @@ enum ComparisonOperator { case Equals; - case Greater; - case GreaterOrEqual; + case GreaterThan; + case GreaterThanOrEqual; case In; - case Less; - case LessOrEqual; + case LessThan; + case LessThanOrEqual; case NotEquals; case NotIn; } diff --git a/src/Processor/Condition/CompareProcessor.php b/src/Processor/Condition/CompareProcessor.php index 71adfc8..d0f6a4a 100644 --- a/src/Processor/Condition/CompareProcessor.php +++ b/src/Processor/Condition/CompareProcessor.php @@ -44,15 +44,15 @@ public function supports(ConditionInterface $condition): bool private function compare(mixed $value, Compare $condition): bool { return match ($condition->operator) { - ComparisonOperator::Equals => $value === $condition->value, - ComparisonOperator::Greater => $value > $condition->value, - ComparisonOperator::GreaterOrEqual => $value >= $condition->value, - ComparisonOperator::In => in_array($value, $condition->value, strict: true), - ComparisonOperator::NotIn => !in_array($value, $condition->value, strict: true), - ComparisonOperator::Less => $value < $condition->value, - ComparisonOperator::LessOrEqual => $value <= $condition->value, - ComparisonOperator::NotEquals => $value !== $condition->value, - default => throw new LogicException( + ComparisonOperator::Equals => $value === $condition->value, + ComparisonOperator::GreaterThan => $value > $condition->value, + ComparisonOperator::GreaterThanOrEqual => $value >= $condition->value, + ComparisonOperator::In => in_array($value, $condition->value, strict: true), + ComparisonOperator::NotIn => !in_array($value, $condition->value, strict: true), + ComparisonOperator::LessThan => $value < $condition->value, + ComparisonOperator::LessThanOrEqual => $value <= $condition->value, + ComparisonOperator::NotEquals => $value !== $condition->value, + default => throw new LogicException( "Condition \"{$condition->operator->name}\" is not implemented.", ), }; diff --git a/tests/Unit/AbstractCollectionTestCase.php b/tests/Unit/AbstractCollectionTestCase.php index 538e881..f8d249c 100644 --- a/tests/Unit/AbstractCollectionTestCase.php +++ b/tests/Unit/AbstractCollectionTestCase.php @@ -353,12 +353,12 @@ public static function getDataForWhereCompareTest(): iterable yield [ [['a' => 1], ['a' => 2], ['a' => 3]], [['a' => 3]], - new Compare(field: 'a', operator: ComparisonOperator::Greater, value: 2), + new Compare(field: 'a', operator: ComparisonOperator::GreaterThan, value: 2), ]; yield [ [['a' => 1], ['a' => 2], ['a' => 3]], [['a' => 2], ['a' => 3]], - new Compare(field: 'a', operator: ComparisonOperator::GreaterOrEqual, value: 2), + new Compare(field: 'a', operator: ComparisonOperator::GreaterThanOrEqual, value: 2), ]; yield [ [['a' => 1], ['a' => 2], ['a' => 3]], @@ -378,12 +378,12 @@ public static function getDataForWhereCompareTest(): iterable yield [ [['a' => 1], ['a' => 2], ['a' => 3]], [['a' => 1]], - new Compare(field: 'a', operator: ComparisonOperator::Less, value: 2), + new Compare(field: 'a', operator: ComparisonOperator::LessThan, value: 2), ]; yield [ [['a' => 1], ['a' => 2], ['a' => 3]], [['a' => 1], ['a' => 2]], - new Compare(field: 'a', operator: ComparisonOperator::LessOrEqual, value: 2), + new Compare(field: 'a', operator: ComparisonOperator::LessThanOrEqual, value: 2), ]; $el1 = new stdClass(); @@ -395,12 +395,12 @@ public static function getDataForWhereCompareTest(): iterable yield [ [$el1, $el2, $el3], [$el3], - new Compare(field: 'test', operator: ComparisonOperator::Greater, value: 2), + new Compare(field: 'test', operator: ComparisonOperator::GreaterThan, value: 2), ]; yield [ [$el1, $el2, $el3], [$el2, $el3], - new Compare(field: 'test', operator: ComparisonOperator::GreaterOrEqual, value: 2), + new Compare(field: 'test', operator: ComparisonOperator::GreaterThanOrEqual, value: 2), ]; yield [ [$el1, $el2, $el3], @@ -420,12 +420,12 @@ public static function getDataForWhereCompareTest(): iterable yield [ [$el1, $el2, $el3], [$el1], - new Compare(field: 'test', operator: ComparisonOperator::Less, value: 2), + new Compare(field: 'test', operator: ComparisonOperator::LessThan, value: 2), ]; yield [ [$el1, $el2, $el3], [$el1, $el2], - new Compare(field: 'test', operator: ComparisonOperator::LessOrEqual, value: 2), + new Compare(field: 'test', operator: ComparisonOperator::LessThanOrEqual, value: 2), ]; }