@@ -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