Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use levenshtein level for better Bundle matching#18799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:2.7fromj0k3r:shortest-levenshtein2
May 17, 2016
Merged

Use levenshtein level for better Bundle matching#18799

fabpot merged 1 commit intosymfony:2.7fromj0k3r:shortest-levenshtein2
May 17, 2016

Conversation

@j0k3r
Copy link
Contributor

QA
Branch?2.7
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
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 onbad bundle exception, from#11210.

$alternative =null;$shortest =null;foreach ($bundleNamesas$bundleName) {// if there's a partial match, return it immediatelyif (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 theforeach. 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.

if ($lev <=strlen($nonExistentBundleName) /3 && ($alternative ===null ||$lev <$shortest)) {$alternative =$bundleName;$shortest =$lev;}

Let say you have these bundles:FoooooBundle andFooBundle and you request the bundleFoodBundle.

  • Without$shortest updated, you'll got a suggestion withFoooooBundle (first matching bundle found)
  • With$shortest upadted, you'll got a suggestion withFooBundle (because it has a better level thanFoooooBundle)

This isn't abug 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?

@javiereguiluz
Copy link
Member

I'd say this is a bug because the variable wasn't updated in the loop. I'm 👍 for the change/fix. Thanks@j0k3r.

@stof
Copy link
Member

👍

@fabpot
Copy link
Member

Thank you@j0k3r.

@fabpotfabpot merged commitac7f74e intosymfony:2.7May 17, 2016
fabpot added a commit that referenced this pull requestMay 17, 2016
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`.```phpif ($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
@j0k3rj0k3r deleted the shortest-levenshtein2 branchMay 18, 2016 07:47
@fabpotfabpot mentioned this pull requestMay 26, 2016
This was referencedJun 6, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@j0k3r@javiereguiluz@stof@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp