Skip to content

Commit

Permalink
feat+fix: add test param min_length + change it position
Browse files Browse the repository at this point in the history
  • Loading branch information
kocoten1992 committed Nov 26, 2022
1 parent a102492 commit fabac5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/StrUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class StrUtil
{
public static function toSearchablePhrases(
string $string,
int $min_length = 1,
string $separator = ' ',
int $limit = PHP_INT_MAX,
int $min_length = 1,
): array {
$string = mb_strtolower($string);

Expand All @@ -35,7 +35,7 @@ public static function toSearchablePhrases(
break;
}

$length = 1;
$length = $min_length;

while ($pointer + $length < $sub_string_length + 1) {
$result[implode('', array_slice($mb_str_split, $pointer, $length))] = true;
Expand Down
20 changes: 20 additions & 0 deletions tests/StrUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ public function test_to_searchable_phrases()

$this->assertEquals(16, count(StrUtil::toSearchablePhrases('léon')));

$this->assertEquals(16, count(StrUtil::toSearchablePhrases('léon')));

$this->assertEquals(
StrUtil::toSearchablePhrases('amélie'),
StrUtil::toSearchablePhrases('AméLie')
);

$this->assertEquals(32, count(StrUtil::toSearchablePhrases('amélie')));

$this->assertEquals(
StrUtil::toSearchablePhrases('amélie', 4),
[
"amél",
"amel",
"améli",
"ameli",
"amélie",
"amelie",
"méli",
"meli",
"mélie",
"melie",
"élie",
"elie",
]
);
}

public function test_replace_once()
Expand Down

0 comments on commit fabac5b

Please sign in to comment.