2727class Application
2828{
2929 /** @var Command[] */
30- protected $ commands = [];
30+ protected array $ commands = [];
3131
3232 /** @var array Raw argv sent to parse() */
33- protected $ argv = [];
33+ protected array $ argv = [];
3434
3535 /** @var array Command aliases [alias => cmd] */
36- protected $ aliases = [];
37-
38- /** @var string */
39- protected $ name ;
40-
41- /** @var string App version */
42- protected $ version = '' ;
36+ protected array $ aliases = [];
4337
4438 /** @var string Ascii art logo */
45- protected $ logo = '' ;
39+ protected string $ logo = '' ;
4640
47- protected $ default = '__default__ ' ;
41+ protected string $ default = '__default__ ' ;
4842
4943 /** @var Interactor */
50- protected $ io ;
44+ protected Interactor $ io ;
5145
5246 /** @var callable The callable to perform exit */
5347 protected $ onExit ;
5448
55- public function __construct (string $ name , string $ version = '0.0.1 ' , callable $ onExit = null )
49+ public function __construct (protected string $ name , protected string $ version = '0.0.1 ' , callable $ onExit = null )
5650 {
57- $ this ->name = $ name ;
58- $ this ->version = $ version ;
59-
60- // @codeCoverageIgnoreStart
61- $ this ->onExit = $ onExit ?? function ($ exitCode = 0 ) {
62- exit ($ exitCode );
63- };
64- // @codeCoverageIgnoreEnd
51+ $ this ->onExit = $ onExit ?? fn (int $ exitCode = 0 ) => exit ($ exitCode );
6552
6653 $ this ->command ('__default__ ' , 'Default command ' , '' , true )->on ([$ this , 'showHelp ' ], 'help ' );
6754 }
6855
6956 /**
7057 * Get the name.
71- *
72- * @return string
7358 */
7459 public function name (): string
7560 {
@@ -78,8 +63,6 @@ public function name(): string
7863
7964 /**
8065 * Get the version.
81- *
82- * @return string
8366 */
8467 public function version (): string
8568 {
@@ -102,8 +85,6 @@ public function commands(): array
10285
10386 /**
10487 * Get the raw argv.
105- *
106- * @return array
10788 */
10889 public function argv (): array
10990 {
@@ -130,14 +111,6 @@ public function logo(string $logo = null)
130111
131112 /**
132113 * Add a command by its name desc alias etc.
133- *
134- * @param string $name
135- * @param string $desc
136- * @param string $alias
137- * @param bool $allowUnknown
138- * @param bool $default
139- *
140- * @return Command
141114 */
142115 public function command (
143116 string $ name ,
@@ -155,12 +128,6 @@ public function command(
155128
156129 /**
157130 * Add a prepred command.
158- *
159- * @param Command $command
160- * @param string $alias
161- * @param bool $default
162- *
163- * @return self
164131 */
165132 public function add (Command $ command , string $ alias = '' , bool $ default = false ): self
166133 {
@@ -192,17 +159,13 @@ public function add(Command $command, string $alias = '', bool $default = false)
192159
193160 /**
194161 * Gets matching command for given argv.
195- *
196- * @param array $argv
197- *
198- * @return Command
199162 */
200163 public function commandFor (array $ argv ): Command
201164 {
202165 $ argv += [null , null , null ];
203166
204167 return
205- // cmd
168+ // cmd
206169 $ this ->commands [$ argv [1 ]]
207170 // cmd alias
208171 ?? $ this ->commands [$ this ->aliases [$ argv [1 ]] ?? null ]
@@ -262,12 +225,8 @@ public function parse(array $argv): Command
262225
263226 /**
264227 * Handle the request, invoke action and call exit handler.
265- *
266- * @param array $argv
267- *
268- * @return mixed
269228 */
270- public function handle (array $ argv )
229+ public function handle (array $ argv ): mixed
271230 {
272231 if (\count ($ argv ) < 2 ) {
273232 return $ this ->showHelp ();
@@ -288,10 +247,6 @@ public function handle(array $argv)
288247
289248 /**
290249 * Get aliases for given command.
291- *
292- * @param Command $command
293- *
294- * @return array
295250 */
296251 protected function aliasesFor (Command $ command ): array
297252 {
@@ -309,10 +264,8 @@ protected function aliasesFor(Command $command): array
309264
310265 /**
311266 * Show help of all commands.
312- *
313- * @return mixed
314267 */
315- public function showHelp ()
268+ public function showHelp (): mixed
316269 {
317270 $ writer = $ this ->io ()->writer ();
318271 $ header = "{$ this ->name }, version {$ this ->version }" ;
@@ -336,12 +289,8 @@ protected function outputHelper(): OutputHelper
336289
337290 /**
338291 * Invoke command action.
339- *
340- * @param Command $command
341- *
342- * @return mixed
343292 */
344- protected function doAction (Command $ command )
293+ protected function doAction (Command $ command ): mixed
345294 {
346295 if ($ command ->name () === '__default__ ' ) {
347296 return $ this ->notFound ();
@@ -351,7 +300,7 @@ protected function doAction(Command $command)
351300 $ command ->interact ($ this ->io ());
352301
353302 if (!$ command ->action () && !\method_exists ($ command , 'execute ' )) {
354- return ;
303+ return null ;
355304 }
356305
357306 $ params = [];
@@ -368,10 +317,8 @@ protected function doAction(Command $command)
368317
369318 /**
370319 * Command not found handler.
371- *
372- * @return mixed
373320 */
374- protected function notFound ()
321+ protected function notFound (): mixed
375322 {
376323 $ available = \array_keys ($ this ->commands () + $ this ->aliases );
377324 $ this ->outputHelper ()->showCommandNotFound ($ this ->argv [1 ], $ available );
0 commit comments