Skip to content

Commit d5731f2

Browse files
committed
Patch In/NotIn logic
1 parent 46be83d commit d5731f2

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/In.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ public function evaluate(mixed $input = null): bool
5353
} else if (!is_array($needle) && is_array($haystack)) {
5454
$result = in_array($needle, $haystack);
5555
} else if (is_array($needle)) {
56-
$result = true;
57-
foreach ($needle as $n) {
58-
if (is_array($haystack)) {
59-
if (!in_array($n, $haystack)) {
56+
if (is_array($haystack)) {
57+
$result = !empty(array_intersect($needle, $haystack));
58+
} else {
59+
$result = true;
60+
foreach ($needle as $n) {
61+
if (!str_contains((string)$haystack, $n)) {
6062
$result = false;
6163
break;
6264
}
63-
} else if (!str_contains((string)$haystack, $n)) {
64-
$result = false;
65-
break;
6665
}
6766
}
6867
}

src/NotIn.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ public function evaluate(mixed $input = null): bool
5353
} else if (!is_array($needle) && is_array($haystack)) {
5454
$result = (!in_array($needle, $haystack));
5555
} else if (is_array($needle)) {
56-
$result = true;
57-
foreach ($needle as $n) {
58-
if (is_array($haystack)) {
59-
if (in_array($n, $haystack)) {
56+
if (is_array($haystack)) {
57+
$result = empty(array_intersect($needle, $haystack));
58+
} else {
59+
$result = true;
60+
foreach ($needle as $n) {
61+
if (str_contains((string)$haystack, $n)) {
6062
$result = false;
6163
break;
6264
}
63-
} else if (str_contains((string)$haystack, $n)) {
64-
$result = false;
65-
break;
6665
}
6766
}
6867
}

0 commit comments

Comments
 (0)