Skip to content

Commit 3c8058c

Browse files
authored
Feature/Add IS NULL and IS NOT NULL filters (#35)
Co-authored-by: Dmytro Zasiadko <[email protected]>
1 parent 3260731 commit 3c8058c

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/Application/CriteriaBuilder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,28 @@ public function filterLike(string $field, $value): self
159159
return $this;
160160
}
161161

162+
/**
163+
* Adds new filter for IS NULL operator
164+
* @param string $field
165+
* @return $this
166+
*/
167+
public function filterIsNull(string $field): self
168+
{
169+
$this->filter($field, Filter::IS_NULL, null);
170+
return $this;
171+
}
172+
173+
/**
174+
* Adds new filter for IS NOT NULL operator
175+
* @param string $field
176+
* @return $this
177+
*/
178+
public function filterIsNotNull(string $field): self
179+
{
180+
$this->filter($field, Filter::IS_NOT_NULL, null);
181+
return $this;
182+
}
183+
162184
/**
163185
* Sets the order by field parameter.
164186
*

src/Domain/Criteria/Filter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ final class Filter implements ValueObject
2727
public const IN = 'in';
2828
public const NOT_IN = 'notIn';
2929
public const LIKE = 'like';
30+
public const IS_NULL = 'isNull';
31+
public const IS_NOT_NULL = 'isNotNull';
3032

3133
/**
3234
* The filter field name.

tests/Application/CriteriaBuilderTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public function testShouldAddFiltersToCriteria(): void
3434
->filterIn('address.state', ['FL', 'NY'])
3535
->filterNotIn('address.zip', [10, 11, 12, 13])
3636
->filterLike('job.title', '%Gangster%')
37+
->filterIsNull('lastActivityDate')
38+
->filterIsNotNull('lastLoginDate')
3739
->build();
3840

39-
$this->assertCount(9, $criteria->filters());
41+
$this->assertCount(11, $criteria->filters());
4042
}
4143

4244
public function testShouldSetOrderByAndOrderType(): void
@@ -60,4 +62,4 @@ public function testShouldSetPageLimitAndPageOffset(): void
6062
$this->assertEquals(50, $criteria->pageLimit());
6163
$this->assertEquals(100, $criteria->pageOffset());
6264
}
63-
}
65+
}

0 commit comments

Comments
 (0)