Skip to content

Commit

Permalink
Consider special cases when comparing filter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Mar 18, 2024
1 parent e15a8cf commit 5d59f95
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Filter/Equal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ public function ignoresCase()
{
return $this->ignoreCase;
}

public function sameAs(Rule $rule): bool
{
if (! $rule instanceof static) {
return false;
}

if ($this->ignoresCase() !== $rule->ignoresCase()) {
return false;
}

if (is_array($this->value)) {
return array_diff($this->value, (array) $rule->getValue()) === [];
}

return parent::sameAs($rule);
}
}
17 changes: 17 additions & 0 deletions src/Filter/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ public function ignoresCase()
{
return $this->ignoreCase;
}

public function sameAs(Rule $rule): bool
{
if (! $rule instanceof static) {
return false;
}

if ($rule->ignoresCase() !== $this->ignoresCase()) {
return false;
}

if (is_array($this->value)) {
return array_diff($this->value, (array) $rule->getValue()) === [];
}

return parent::sameAs($rule);
}
}
17 changes: 17 additions & 0 deletions src/Filter/Unequal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ public function ignoresCase()
{
return $this->ignoreCase;
}

public function sameAs(Rule $rule): bool
{
if (! $rule instanceof static) {
return false;
}

if ($this->ignoresCase() !== $rule->ignoresCase()) {
return false;
}

if (is_array($this->value)) {
return array_diff($this->value, (array) $rule->getValue()) === [];
}

return parent::sameAs($rule);
}
}
17 changes: 17 additions & 0 deletions src/Filter/Unlike.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ public function ignoresCase()
{
return $this->ignoreCase;
}

public function sameAs(Rule $rule): bool
{
if (! $rule instanceof static) {
return false;
}

if ($rule->ignoresCase() !== $this->ignoresCase()) {
return false;
}

if (is_array($this->value)) {
return array_diff($this->value, (array) $rule->getValue()) === [];
}

return parent::sameAs($rule);
}
}

0 comments on commit 5d59f95

Please sign in to comment.