Skip to content

Commit 49d3c4b

Browse files
authored
Merge pull request #69 from wshafer/master
Adds neq filter
2 parents d366439 + 11c2a6d commit 49d3c4b

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Same if you want different settings per entity/table, it should be done by a spe
1818
- [With simple SQL](#with-sql-applicator)
1919
- [Supported filters](#supported-filters)
2020
- [Equals](#equals---eq-)
21+
- [Not Equals](#not-equals---neq-)
2122
- [Greater than](#greater-than---gt-)
2223
- [Greater than or Equals](#greater-than-or-equals---gte-)
2324
- [Lower than](#lower-than---lt-)
@@ -153,6 +154,11 @@ GET http://host/endpoint/?field=value
153154
```
154155
_Both examples ☝ are equal_
155156

157+
### Not Equals - NEQ (!=)
158+
```http request
159+
GET http://host/endpoint/?field[neq]=value
160+
```
161+
156162
### Greater Than - GT (>)
157163
```http request
158164
GET http://host/endpoint/?field[gt]=value

src/Constant/Filter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
final class Filter
66
{
77
public const EQUALS = 'eq';
8+
public const NOT_EQUALS = 'neq';
89
public const LESS_THEN_OR_EQUAL = 'lte';
910
public const LESS_THEN = 'lt';
1011
public const GREATER_THAN = 'gt';

src/Service/FilterFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public function createFilter(string $column, string $filter, Value $value, strin
1818
switch (mb_strtolower($filter)) {
1919
case Filter::EQUALS:
2020
return new FilterWithOperator($column, $value, '=', $title ?? Filter::EQUALS);
21+
case Filter::NOT_EQUALS:
22+
return new FilterWithOperator($column, $value, '!=', $title ?? Filter::NOT_EQUALS);
2123
case Filter::GREATER_THAN:
2224
return new FilterWithOperator($column, $value, '>', $title ?? Filter::GREATER_THAN);
2325
case Filter::LESS_THEN:

tests/Service/FilterApplicatorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ public function provideFilter(): array
100100
'SELECT * FROM table WHERE public = 1 AND col = :col_eq',
101101
['col_eq' => 'val'],
102102
],
103+
'sql - neq' => [
104+
$sqlApplicator,
105+
[new FilterWithOperator('col', new Value('val'), '!=', 'neq')],
106+
'SELECT * FROM table WHERE public != 1',
107+
'SELECT * FROM table WHERE public != 1 AND col != :col_neq',
108+
['col_neq' => 'val'],
109+
],
103110
'sql - gt' => [
104111
$sqlApplicator,
105112
[new FilterWithOperator('col', new Value('val'), '>', 'gt')],

tests/Service/FilterFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function provideFilters(): array
5555
return [
5656
// filter, expectedFilterClass, ?expectedTitle, ?rawValue, ?expectedValue
5757
'eq' => ['eq', FilterWithOperator::class],
58+
'neq' => ['neq', FilterWithOperator::class],
5859
'gt' => ['gt', FilterWithOperator::class],
5960
'gte' => ['gte', FilterWithOperator::class],
6061
'lt' => ['lt', FilterWithOperator::class],

0 commit comments

Comments
 (0)