Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: rename ComparisonOperator values #11

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOD.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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(),
);
Expand Down
8 changes: 4 additions & 4 deletions src/Enum/ComparisonOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
18 changes: 9 additions & 9 deletions src/Processor/Condition/CompareProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
),
};
Expand Down
16 changes: 8 additions & 8 deletions tests/Unit/AbstractCollectionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand All @@ -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();
Expand All @@ -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],
Expand All @@ -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),
];
}

Expand Down
Loading