3737 * Class App - A lite CLI Application
3838 *
3939 * @package Inhere\Console
40+ * @deprecated please use package: toolkit/pflag
4041 */
4142class App
4243{
43- /** @var self */
44- public static $ global ;
44+ /** @var self|null */
45+ public static ? self $ global = null ;
4546
4647 private const COMMAND_CONFIG = [
4748 'desc ' => '' ,
@@ -50,12 +51,12 @@ class App
5051 ];
5152
5253 /** @var string Current dir */
53- private $ pwd ;
54+ private string $ pwd ;
5455
5556 /**
5657 * @var array
5758 */
58- protected $ params = [
59+ protected array $ params = [
5960 'name ' => 'My application ' ,
6061 'desc ' => 'My command line application ' ,
6162 'version ' => '0.2.1 '
@@ -64,37 +65,37 @@ class App
6465 /**
6566 * @var array Parsed from `arg0 name=val var2=val2`
6667 */
67- private $ args ;
68+ private mixed $ args ;
6869
6970 /**
7071 * @var array Parsed from `--name=val --var2=val2 -d`
7172 */
72- private $ opts ;
73+ private mixed $ opts ;
7374
7475 /**
7576 * @var string
7677 */
77- private $ script ;
78+ private mixed $ script ;
7879
7980 /**
8081 * @var string
8182 */
82- private $ command = '' ;
83+ private string $ command = '' ;
8384
8485 /**
8586 * @var array User add commands
8687 */
87- private $ commands = [];
88+ private array $ commands = [];
8889
8990 /**
9091 * @var array Command messages for the commands
9192 */
92- private $ messages = [];
93+ private array $ messages = [];
9394
9495 /**
9596 * @var int
9697 */
97- private $ keyWidth = 12 ;
98+ private int $ keyWidth = 12 ;
9899
99100 /**
100101 * @return static
@@ -233,7 +234,7 @@ public function stop(int $code = 0): void
233234 * @return mixed
234235 * @throws InvalidArgumentException
235236 */
236- public function runHandler (string $ command , $ handler )
237+ public function runHandler (string $ command , mixed $ handler ): mixed
237238 {
238239 if (is_string ($ handler )) {
239240 // function name
@@ -315,19 +316,19 @@ public function addByConfig(callable $handler, array $config): void
315316 /**
316317 * @param string $command
317318 * @param callable $handler
318- * @param null| array|string $config
319+ * @param array|string|null $config
319320 */
320- public function add (string $ command , callable $ handler , $ config = null ): void
321+ public function add (string $ command , callable $ handler , array | string $ config = null ): void
321322 {
322323 $ this ->addCommand ($ command , $ handler , $ config );
323324 }
324325
325326 /**
326327 * @param string $command
327328 * @param callable $handler
328- * @param null| array|string $config
329+ * @param array|string|null $config
329330 */
330- public function addCommand (string $ command , callable $ handler , $ config = null ): void
331+ public function addCommand (string $ command , callable $ handler , array | string $ config = null ): void
331332 {
332333 if (!$ command ) {
333334 throw new InvalidArgumentException ('Invalid arguments for add command ' );
@@ -463,45 +464,45 @@ public function displayCommandHelp(string $name): void
463464 }
464465
465466 /**
466- * @param string| int $name
467- * @param mixed $default
467+ * @param int|string $name
468+ * @param mixed|null $default
468469 *
469470 * @return mixed|null
470471 */
471- public function getArg ($ name , $ default = null )
472+ public function getArg (int | string $ name , mixed $ default = null ): mixed
472473 {
473474 return $ this ->args [$ name ] ?? $ default ;
474475 }
475476
476477 /**
477- * @param string| int $name
478+ * @param int|string $name
478479 * @param int $default
479480 *
480481 * @return int
481482 */
482- public function getIntArg ($ name , int $ default = 0 ): int
483+ public function getIntArg (int | string $ name , int $ default = 0 ): int
483484 {
484485 return (int )$ this ->getArg ($ name , $ default );
485486 }
486487
487488 /**
488- * @param string| int $name
489+ * @param int|string $name
489490 * @param string $default
490491 *
491492 * @return string
492493 */
493- public function getStrArg ($ name , string $ default = '' ): string
494+ public function getStrArg (int | string $ name , string $ default = '' ): string
494495 {
495496 return (string )$ this ->getArg ($ name , $ default );
496497 }
497498
498499 /**
499500 * @param string $name
500- * @param mixed $default
501+ * @param mixed|null $default
501502 *
502503 * @return mixed|null
503504 */
504- public function getOpt (string $ name , $ default = null )
505+ public function getOpt (string $ name , mixed $ default = null ): mixed
505506 {
506507 return $ this ->opts [$ name ] ?? $ default ;
507508 }
@@ -688,7 +689,7 @@ public function setMetas(array $params): void
688689 *
689690 * @return mixed|string|null
690691 */
691- public function getParam (string $ key , $ default = null )
692+ public function getParam (string $ key , $ default = null ): mixed
692693 {
693694 return $ this ->params [$ key ] ?? $ default ;
694695 }
@@ -697,7 +698,7 @@ public function getParam(string $key, $default = null)
697698 * @param string $key
698699 * @param mixed $val
699700 */
700- public function setParam (string $ key , $ val ): void
701+ public function setParam (string $ key , mixed $ val ): void
701702 {
702703 $ this ->params [$ key ] = $ val ;
703704 }
0 commit comments