@@ -608,6 +608,10 @@ public function find($name)
608
608
}
609
609
}
610
610
611
+ if ($ this ->has ($ name )) {
612
+ return $ this ->get ($ name );
613
+ }
614
+
611
615
$ allCommands = $ this ->commandLoader ? array_merge ($ this ->commandLoader ->getNames (), array_keys ($ this ->commands )) : array_keys ($ this ->commands );
612
616
$ expr = preg_replace_callback ('{([^:]+|)} ' , function ($ matches ) { return preg_quote ($ matches [1 ]).'[^:]* ' ; }, $ name );
613
617
$ commands = preg_grep ('{^ ' .$ expr .'} ' , $ allCommands );
@@ -645,15 +649,7 @@ public function find($name)
645
649
// filter out aliases for commands which are already on the list
646
650
if (\count ($ commands ) > 1 ) {
647
651
$ 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 ) {
657
653
if (!$ commandList [$ nameOrAlias ] instanceof Command) {
658
654
$ commandList [$ nameOrAlias ] = $ this ->commandLoader ->get ($ nameOrAlias );
659
655
}
@@ -662,14 +658,8 @@ public function find($name)
662
658
663
659
$ aliases [$ nameOrAlias ] = $ commandName ;
664
660
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
+ }));
673
663
}
674
664
675
665
$ exact = \in_array ($ name , $ commands , true ) || isset ($ aliases [$ name ]);
0 commit comments