Skip to content

Commit 41197c2

Browse files
committed
Filter: Implement hasNotValue() & matchHasnotValue() methods
1 parent 4cd3656 commit 41197c2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Filter.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,34 @@ protected function matchHasValue($rule, $row)
182182
return ! empty($this->extractValue($rule->getColumn(), $row));
183183
}
184184

185+
/**
186+
* Create a rule that applies rows where a column has no values, i.e. to all
187+
* rows where this column hasn't been set.
188+
*
189+
* Performs ! isset() | IS NULL actions
190+
*
191+
* @param string $column
192+
*
193+
* @return HasNotValue
194+
*/
195+
public static function hasNotValue($column)
196+
{
197+
return new HasNotValue($column, '');
198+
}
199+
200+
/**
201+
* Get whether the given rule's column is null|doesn't contain any values
202+
*
203+
* @param HasNotValue $rule
204+
* @param object $row
205+
*
206+
* @return bool
207+
*/
208+
public function matchHasNotValue(HasNotValue $rule, $row)
209+
{
210+
return ! $this->matchHasValue($rule, $row);
211+
}
212+
185213
/**
186214
* Create a rule that matches rows with a column that **equals** the given value
187215
*
@@ -449,6 +477,8 @@ protected function performMatch(Rule $rule, $row)
449477
return $this->matchUnequal($rule, $row);
450478
case $rule instanceof HasValue:
451479
return $this->matchHasValue($rule, $row);
480+
case $rule instanceof HasNotValue:
481+
return $this->matchHasNotValue($rule, $row);
452482
default:
453483
throw new InvalidArgumentException(sprintf(
454484
'Unable to match filter. Rule type %s is unknown',

0 commit comments

Comments
 (0)