Permalink
Browse files

feature #17484 [FrameworkBundle][DX] Add Levenshtein suggesters to Ab…

…stractConfigCommand (kix)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[FrameworkBundle][DX] Add Levenshtein suggesters to AbstractConfigCommand

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | none

It could be helpful to output the best guesses for bundle names and container extension aliases when one could not be found by the exact query.

Perhaps, I could regroup the logic so that it only looks through bundle names if the `Bundle` suffix is present, but I guess this might narrow the use case scope here.

Commits
-------

3c0b0ae Add Levenshtein suggesters to AbstractConfigCommand
  • Loading branch information...
fabpot committed Mar 2, 2016
2 parents bcf0e91 + 3c0b0ae commit 5c34ae467816d449110ae380d19f4a6ebfa00664
Showing with 27 additions and 4 deletions.
  1. +27 −4 src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php
@@ -52,6 +52,8 @@ protected function listBundles($output)
protected function findExtension($name)
{
$bundles = $this->initializeBundles();
$minScore = INF;
foreach ($bundles as $bundle) {
if ($name === $bundle->getName()) {
if (!$bundle->getContainerExtension()) {
@@ -61,16 +63,37 @@ protected function findExtension($name)
return $bundle->getContainerExtension();
}
$distance = levenshtein($name, $bundle->getName());
if ($distance < $minScore) {
$guess = $bundle->getName();
$minScore = $distance;
}
$extension = $bundle->getContainerExtension();
if ($extension && $name === $extension->getAlias()) {
return $extension;
if ($extension) {
if ($name === $extension->getAlias()) {
return $extension;
}
$distance = levenshtein($name, $extension->getAlias());
if ($distance < $minScore) {
$guess = $extension->getAlias();
$minScore = $distance;
}
}
}
if ('Bundle' !== substr($name, -6)) {
$message = sprintf('No extensions with configuration available for "%s"', $name);
$message = sprintf('No extensions with configuration available for "%s".', $name);
} else {
$message = sprintf('No extension with alias "%s" is enabled', $name);
$message = sprintf('No extension with alias "%s" is enabled.', $name);
}
if (isset($guess) && $minScore < 3) {
$message .= sprintf("\n\nDid you mean \"%s\"?", $guess);
}
throw new \LogicException($message);

0 comments on commit 5c34ae4

Please sign in to comment.