Skip to content

Commit

Permalink
Filter: Implement hasNotValue() & matchHasnotValue() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Nov 15, 2021
1 parent 4cd3656 commit 41197c2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,34 @@ protected function matchHasValue($rule, $row)
return ! empty($this->extractValue($rule->getColumn(), $row));
}

/**
* Create a rule that applies rows where a column has no values, i.e. to all
* rows where this column hasn't been set.
*
* Performs ! isset() | IS NULL actions
*
* @param string $column
*
* @return HasNotValue
*/
public static function hasNotValue($column)
{
return new HasNotValue($column, '');
}

/**
* Get whether the given rule's column is null|doesn't contain any values
*
* @param HasNotValue $rule
* @param object $row
*
* @return bool
*/
public function matchHasNotValue(HasNotValue $rule, $row)
{
return ! $this->matchHasValue($rule, $row);
}

/**
* Create a rule that matches rows with a column that **equals** the given value
*
Expand Down Expand Up @@ -449,6 +477,8 @@ protected function performMatch(Rule $rule, $row)
return $this->matchUnequal($rule, $row);
case $rule instanceof HasValue:
return $this->matchHasValue($rule, $row);
case $rule instanceof HasNotValue:
return $this->matchHasNotValue($rule, $row);
default:
throw new InvalidArgumentException(sprintf(
'Unable to match filter. Rule type %s is unknown',
Expand Down

0 comments on commit 41197c2

Please sign in to comment.