Skip to content

Commit d39905d

Browse files
authored
Merge pull request #13 from permafrost-dev/fix-matchesAny-bug
Fix matchesAny nested array bug
2 parents e413264 + 5345dff commit d39905d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Support/Arr.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ public static function matchesAny($strings, array $values, bool $allowRegex = tr
4646
$strings = [$strings];
4747
}
4848

49-
return collect($strings)->map(function (string $str) use ($values, $allowRegex) {
50-
return self::matches($str, $values, $allowRegex);
49+
return collect($strings)->map(function ($str) use ($values, $allowRegex) {
50+
if (is_array($str)) {
51+
return self::matchesAny($str, $values, $allowRegex);
52+
}
53+
54+
return self::matches((string)$str, $values, $allowRegex);
5155
})->filter(function ($value) {
5256
return $value;
5357
})->count() > 0;

tests/Support/ArrTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,16 @@ public function it_matches_delimited_regex_patterns()
3434
$this->assertTrue(Arr::matches('test', ['/^te.+$/', 'one']));
3535
$this->assertFalse(Arr::matches('test', ['/^Test$/', '/^one$/']));
3636
}
37+
38+
/** @test */
39+
public function it_matches_any_string_against_other_strings()
40+
{
41+
$this->assertTrue(Arr::matchesAny(['one', 'two'], ['abc', 'two']));
42+
}
43+
44+
/** @test */
45+
public function it_matches_any_nested_array_of_strings()
46+
{
47+
$this->assertTrue(Arr::matchesAny([ 'def', ['one', [ 'two' ] ] ], ['abc', 'two']));
48+
}
3749
}

0 commit comments

Comments
 (0)