From e6698a8f39184decd19f09750cbd95b502227f83 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:00:49 +0200 Subject: [PATCH] remove unused function sortByLevenshtein() --- src/Widget/RegionService.php | 22 ---------------------- test/Widget/RegionServiceTest.php | 19 ------------------- 2 files changed, 41 deletions(-) diff --git a/src/Widget/RegionService.php b/src/Widget/RegionService.php index 5f37f7a4..d64cc96e 100644 --- a/src/Widget/RegionService.php +++ b/src/Widget/RegionService.php @@ -100,26 +100,4 @@ public function getItemByTranslatedName($translatedName, $translatedLanguage) } } } - - /** - * Sort items according to Levenshtein distance, the higher the match the higher the value. - * But usort sorts by default from small to large, first item has a smaller value. - * So the high Levenshtein values need to get before the smaller onces and therefore they need to return -1 - * - * @param $matches - * @param $searchString - * @return $matches - */ - public function sortByLevenshtein($matches, $searchString) - { - usort( - $matches, - function ($a, $b) use ($searchString) { - $levA = levenshtein($searchString, $a); - $levB = levenshtein($searchString, $b); - return $levA === $levB ? 0 : ($levA > $levB ? -1 : 1); - } - ); - return $matches; - } } diff --git a/test/Widget/RegionServiceTest.php b/test/Widget/RegionServiceTest.php index e0ec6d32..efe3c6a8 100644 --- a/test/Widget/RegionServiceTest.php +++ b/test/Widget/RegionServiceTest.php @@ -85,23 +85,4 @@ public function it_will_return_null_if_a_name_does_not_match(): void $this->regionService->getItemByName('Liezele') ); } - - /** - * @test - */ - public function it_can_sort_by_levenshtein(): void - { - $searchString = 'Zele'; - $this->assertEquals( - [ - 'Zele + deelgemeenten', - 'Zelem (Halen)', - 'Zele (Zele)', - ], - $this->regionService->sortByLevenshtein( - $this->regionService->getAutocompletResults($searchString), - $searchString - ) - ); - } }