diff --git a/CHANGELOG.md b/CHANGELOG.md index f27bc5a..00cf835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - New #173, #184: Add `$caseSensitive` parameter to `Like` filter to control whether the search must be case-sensitive or not (@arogachev) - Chg #163: Rename `FilterableDataInterface::withFilterHandlers()` to `FilterableDataInterface::withAddedFilterHandlers()` (@samdark) +- Enh #190: Use `str_contains` for case-sensitive match in `LikeHandler` (@samdark) ## 1.0.1 January 25, 2023 diff --git a/src/Reader/Iterable/FilterHandler/LikeHandler.php b/src/Reader/Iterable/FilterHandler/LikeHandler.php index d6941ac..e07119f 100644 --- a/src/Reader/Iterable/FilterHandler/LikeHandler.php +++ b/src/Reader/Iterable/FilterHandler/LikeHandler.php @@ -30,9 +30,8 @@ public function match(object|array $item, FilterInterface $filter, array $iterab return false; } - /** @infection-ignore-all MBString No suitable test case was found yet. */ return $filter->isCaseSensitive() === true - ? mb_strpos($itemValue, $filter->getValue()) !== false + ? str_contains($itemValue, $filter->getValue()) : mb_stripos($itemValue, $filter->getValue()) !== false; } } diff --git a/tests/Reader/Iterable/FilterHandler/LikeHandlerTest.php b/tests/Reader/Iterable/FilterHandler/LikeHandlerTest.php index 3b0b5d8..dc4a889 100644 --- a/tests/Reader/Iterable/FilterHandler/LikeHandlerTest.php +++ b/tests/Reader/Iterable/FilterHandler/LikeHandlerTest.php @@ -34,6 +34,8 @@ public static function matchDataProvider(): array [false, ['id' => 1, 'value' => 'Great Cat Fighter'], 'id', '1', true], [true, ['id' => 1, 'value' => '๐Ÿ™๐Ÿ™‚๐Ÿ™'], 'value', '๐Ÿ™‚', true], [true, ['id' => 1, 'value' => 'ะŸั€ะธะฒะตั‚ ะผะธั€'], 'value', ' ', true], + + [true, ['id' => 1, 'value' => 'das ร–l'], 'value', 'รถl', false], ]; }