8000 minor #35734 [Console] Inline exact-match handling with 4.4 (chalasr) · symfony/symfony@334f020 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 334f020

Browse files
committed
minor #35734 [Console] Inline exact-match handling with 4.4 (chalasr)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Inline exact-match handling with 4.4 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #35696 (comment) | License | MIT | Doc PR | - This reduces the patch for #35696 (not released yet), inlining 3.4's code with 4.4 which was not impacted by the fixed bug. The reverted logic was useless starting from 4.4. Thanks @stof for the hint. Commits ------- e13470c [Console] Inline exact-match handling with 4.4
2 parents b92168c + e13470c commit 334f020

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ public function find($name)
608608
}
609609
}
610610

611+
if ($this->has($name)) {
612+
return $this->get($name);
613+
}
614+
611615
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
612616
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
613617
$commands = preg_grep('{^'.$expr.'}', $allCommands);
@@ -645,15 +649,7 @@ public function find($name)
645649
// filter out aliases for commands which are already on the list
646650
if (\count($commands) > 1) {
647651
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
648-
649-
if (isset($commandList[$name])) {
650-
return $this->get($name);
651-
}
652-
653-
foreach ($commands as $k => $nameOrAlias) {
654-
if ($nameOrAlias === $name) {
655-
return $this->get($nameOrAlias);
656-
}
652+
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
657653
if (!$commandList[$nameOrAlias] instanceof Command) {
658654
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
659655
}
@@ -662,14 +658,8 @@ public function find($name)
662658

663659
$aliases[$nameOrAlias] = $commandName;
664660

665-
if ($commandName === $nameOrAlias || !\in_array($commandName, $commands)) {
666-
continue;
667-
}
668-
669-
unset($commands[$k]);
670-
}
671-
672-
$commands = array_unique($commands);
661+
return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
662+
}));
673663
}
674664

675665
$exact = \in_array($name, $commands, true) || isset($aliases[$name]);

0 commit comments

Comments
 (0)
0