Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Filter/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ public function __clone()
}
}

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

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

$theirRules = iterator_to_array($rule);
foreach ($this->rules as $myRule) {
$found = false;
foreach ($theirRules as $i => $theirRule) {
if ($myRule->sameAs($theirRule)) {
unset($theirRules[$i]);
$found = true;
break;
}
}

if (! $found) {
return false;
}
}

return true;
}

/**
* Get an iterator this chain's rules
*
Expand Down
7 changes: 7 additions & 0 deletions src/Filter/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function __clone()
}
}

public function sameAs(Rule $rule): bool
{
return $rule instanceof static
&& $rule->getColumn() === $this->getColumn()
&& $rule->getValue() === $this->getValue();
}

/**
* Set this condition's column
*
Expand Down
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 @@
{
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()) === [];

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #2 $arrays of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #1 $array of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #2 $arrays of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #1 $array of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #2 $arrays of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #1 $array of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #2 $arrays of function array_diff expects an array of values castable to string, array<mixed, mixed> given.

Check failure on line 43 in src/Filter/Equal.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #1 $array of function array_diff expects an array of values castable to string, array<mixed, mixed> given.
}

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);
}
}
8 changes: 8 additions & 0 deletions src/Filter/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@

interface Rule
{
/**
* Get whether the given rule is semantically the same as this one
*
* @param Rule $rule
*
* @return bool
*/
public function sameAs(Rule $rule): bool;
}
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);
}
}
Loading