Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
bug #18799 Use levenshtein level for better Bundle matching (j0k3r)
This PR was merged into the 2.7 branch. Discussion ---------- Use levenshtein level for better Bundle matching | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | _I've targetted 2.7 branch since this was introduced in the 2.6 version but the 2.6 isn't maintain anymore._ **TL;DR:** I found unused code in bad bundle exception when Symfony try to find the best bundle to fix the typo. Should we remove that code (and got a potential lower matching bundle name) or keep it and make it work? ----- I've noticed that a part of the code wasn't used when determining which bundle typo was written on _bad bundle exception_, from #11210. ```php $alternative = null; $shortest = null; foreach ($bundleNames as $bundleName) { // if there's a partial match, return it immediately if (false !== strpos($bundleName, $nonExistentBundleName)) { return $bundleName; } $lev = levenshtein($nonExistentBundleName, $bundleName); if ($lev <= strlen($nonExistentBundleName) / 3 && ($alternative === null || $lev < $shortest)) { $alternative = $bundleName; } } ``` In this snippet, the `$shortest` wasn't update in the `foreach`. Reading the code, I guess it was supposed to add an even better accuracy when multiple bundle matche the typo'd bundle name. Which mean when an alternative is found, we have to assign the level `$lev` from that match to `$shortest`. ```php if ($lev <= strlen($nonExistentBundleName) / 3 && ($alternative === null || $lev < $shortest)) { $alternative = $bundleName; $shortest = $lev; } ``` Let say you have these bundles: `FoooooBundle` and `FooBundle` and you request the bundle `FoodBundle`. - Without `$shortest` updated, you'll got a suggestion with `FoooooBundle` (first matching bundle found) - With `$shortest` upadted, you'll got a suggestion with `FooBundle` (because it has a better level than `FoooooBundle`) This isn't a _bug fix_ since this is only supposed to help developper but not the final user. **Question is**: should we keep that level comparison or just remove it? Commits ------- ac7f74e Use levenshtein level for better Bundle matching
- Loading branch information