Skip to content
Permalink
Browse files

minor #31420 [Console] optimisation getting the command when finding …

…(Simperfit)

This PR was submitted for the 4.3 branch but it was merged into the 4.4-dev branch instead (closes #31420).

Discussion
----------

[Console] optimisation getting the command when finding

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | none  <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |
<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Following discussion with @chalasr in here #31261 (comment), first commit will be deleted  when the other PR is merged.

Commits
-------

3d6b303 [Console] Optimisation on getting the command
  • Loading branch information...
chalasr committed May 14, 2019
2 parents e19db43 + 3d6b303 commit b563fe6a9c916a86988e9097ae3187964095b9d3
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/Symfony/Component/Console/Application.php
@@ -623,6 +623,10 @@ public function find($name)
}
}
if ($this->has($name)) {
return $this->get($name);
}
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
$commands = preg_grep('{^'.$expr.'}', $allCommands);
@@ -663,8 +667,7 @@ public function find($name)
}));
}
$exact = \in_array($name, $commands, true) || isset($aliases[$name]);
if (\count($commands) > 1 && !$exact) {
if (\count($commands) > 1) {
$usableWidth = $this->terminal->getWidth() - 10;
$abbrevs = array_values($commands);
$maxLen = 0;
@@ -684,7 +687,7 @@ public function find($name)
throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands));
}
return $this->get($exact ? $name : reset($commands));
return $this->get(reset($commands));
}
/**

0 comments on commit b563fe6

Please sign in to comment.
You can’t perform that action at this time.