1616 */
1717namespace Cake \Command ;
1818
19- use Cake \Console \Arguments ;
2019use Cake \Console \BaseCommand ;
2120use Cake \Console \CommandCollection ;
2221use Cake \Console \CommandCollectionAwareInterface ;
23- use Cake \Console \ConsoleIoInterface ;
2422use Cake \Console \ConsoleOptionParser ;
2523use ReflectionClass ;
2624
@@ -99,50 +97,44 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
9997 /**
10098 * Main function Prints out the list of commands.
10199 *
102- * @param \Cake\Console\Arguments $args The command arguments.
103- * @param \Cake\Console\ConsoleIoInterface $io The console io
104100 * @return int|null
105101 */
106- public function execute (Arguments $ args , ConsoleIoInterface $ io ): ?int
102+ public function execute (): ?int
107103 {
108- return match ($ args ->getArgument ('mode ' )) {
109- 'commands ' => $ this ->getCommands ($ args , $ io ),
110- 'subcommands ' => $ this ->getSubcommands ($ args , $ io ),
111- 'options ' => $ this ->getOptions ($ args , $ io ),
104+ return match ($ this -> args ->getArgument ('mode ' )) {
105+ 'commands ' => $ this ->getCommands (),
106+ 'subcommands ' => $ this ->getSubcommands (),
107+ 'options ' => $ this ->getOptions (),
112108 default => static ::CODE_ERROR ,
113109 };
114110 }
115111
116112 /**
117113 * Get the list of defined commands.
118114 *
119- * @param \Cake\Console\Arguments $args The command arguments.
120- * @param \Cake\Console\ConsoleIoInterface $io The console io
121115 * @return int
122116 */
123- protected function getCommands (Arguments $ args , ConsoleIoInterface $ io ): int
117+ protected function getCommands (): int
124118 {
125119 $ options = [];
126120 foreach ($ this ->commands as $ key => $ value ) {
127121 $ parts = explode (' ' , $ key );
128122 $ options [] = $ parts [0 ];
129123 }
130124 $ options = array_unique ($ options );
131- $ io ->out (implode (' ' , $ options ));
125+ $ this -> io ->out (implode (' ' , $ options ));
132126
133127 return static ::CODE_SUCCESS ;
134128 }
135129
136130 /**
137131 * Get the list of defined sub-commands.
138132 *
139- * @param \Cake\Console\Arguments $args The command arguments.
140- * @param \Cake\Console\ConsoleIoInterface $io The console io
141133 * @return int
142134 */
143- protected function getSubcommands (Arguments $ args , ConsoleIoInterface $ io ): int
135+ protected function getSubcommands (): int
144136 {
145- $ name = $ args ->getArgument ('command ' );
137+ $ name = $ this -> args ->getArgument ('command ' );
146138 if ($ name === null || $ name === '' ) {
147139 return static ::CODE_SUCCESS ;
148140 }
@@ -161,22 +153,20 @@ protected function getSubcommands(Arguments $args, ConsoleIoInterface $io): int
161153 }
162154 }
163155 $ options = array_unique ($ options );
164- $ io ->out (implode (' ' , $ options ));
156+ $ this -> io ->out (implode (' ' , $ options ));
165157
166158 return static ::CODE_SUCCESS ;
167159 }
168160
169161 /**
170162 * Get the options for a command or subcommand
171163 *
172- * @param \Cake\Console\Arguments $args The command arguments.
173- * @param \Cake\Console\ConsoleIoInterface $io The console io
174164 * @return int|null
175165 */
176- protected function getOptions (Arguments $ args , ConsoleIoInterface $ io ): ?int
166+ protected function getOptions (): ?int
177167 {
178- $ name = $ args ->getArgument ('command ' );
179- $ subcommand = $ args ->getArgument ('subcommand ' );
168+ $ name = $ this -> args ->getArgument ('command ' );
169+ $ subcommand = $ this -> args ->getArgument ('subcommand ' );
180170
181171 $ options = [];
182172 foreach ($ this ->commands as $ key => $ value ) {
@@ -191,28 +181,21 @@ protected function getOptions(Arguments $args, ConsoleIoInterface $io): ?int
191181 continue ;
192182 }
193183
194- // Handle class strings
195- if (is_string ($ value )) {
196- $ reflection = new ReflectionClass ($ value );
197- $ value = $ reflection ->newInstance ();
198- assert ($ value instanceof BaseCommand);
199- }
200-
201- if (method_exists ($ value , 'getOptionParser ' )) {
202- /** @var \Cake\Console\ConsoleOptionParser $parser */
203- $ parser = $ value ->getOptionParser ();
184+ $ reflection = new ReflectionClass ($ value );
185+ $ value = $ reflection ->newInstance ($ this ->io );
186+ assert ($ value instanceof BaseCommand);
204187
205- foreach ( $ parser -> options () as $ name => $ option ) {
206- $ options [] = " -- { $ name }" ;
207- $ short = $ option -> short () ;
208- if ( $ short) {
209- $ options [] = " - { $ short }" ;
210- }
188+ $ parser = $ value -> getOptionParser ();
189+ foreach ( $ parser -> options () as $ name => $ option ) {
190+ $ options [] = " -- { $ name }" ;
191+ $ short = $ option -> short ();
192+ if ( $ short ) {
193+ $ options [] = " - { $ short }" ;
211194 }
212195 }
213196 }
214197 $ options = array_unique ($ options );
215- $ io ->out (implode (' ' , $ options ));
198+ $ this -> io ->out (implode (' ' , $ options ));
216199
217200 return static ::CODE_SUCCESS ;
218201 }
0 commit comments