2525use Inhere \Console \Util \Helper ;
2626use Inhere \Console \Util \Interact ;
2727use InvalidArgumentException ;
28+ use JetBrains \PhpStorm \NoReturn ;
2829use Throwable ;
2930use Toolkit \Cli \Helper \FlagHelper ;
3031use Toolkit \Cli \Style ;
@@ -66,14 +67,14 @@ abstract class AbstractApplication implements ApplicationInterface
6667 use SimpleEventAwareTrait;
6768
6869 /** @var array */
69- protected static $ internalCommands = [
70+ protected static array $ internalCommands = [
7071 'version ' => 'Show application version information ' ,
7172 'help ' => 'Show application help information ' ,
7273 'list ' => 'List all group and alone commands ' ,
7374 ];
7475
7576 /** @var array Application runtime stats */
76- protected $ stats = [
77+ protected array $ stats = [
7778 'startTime ' => 0 ,
7879 'endTime ' => 0 ,
7980 'startMemory ' => 0 ,
@@ -83,19 +84,19 @@ abstract class AbstractApplication implements ApplicationInterface
8384 /**
8485 * @var string
8586 */
86- public $ delimiter = ': ' ; // '/' ':'
87+ public string $ delimiter = ': ' ; // '/' ':'
8788
8889 /**
8990 * @var string
9091 */
91- protected $ commandName = '' ;
92+ protected string $ commandName = '' ;
9293
9394 /**
9495 * @var string Command delimiter char. e.g dev:serve
9596 */
9697
9798 /** @var array Application config data */
98- protected $ config = [
99+ protected array $ config = [
99100 'name ' => 'My Console Application ' ,
100101 'desc ' => 'This is my console application ' ,
101102 'version ' => '0.5.1 ' ,
@@ -124,17 +125,17 @@ abstract class AbstractApplication implements ApplicationInterface
124125 /**
125126 * @var Router
126127 */
127- protected $ router ;
128+ protected Router $ router ;
128129
129130 /**
130131 * @var ErrorHandlerInterface Can custom error handler
131132 */
132- protected $ errorHandler ;
133+ protected ErrorHandlerInterface $ errorHandler ;
133134
134135 /**
135136 * @var Controller[]
136137 */
137- protected $ groupObjects = [];
138+ protected array $ groupObjects = [];
138139
139140 /**
140141 * Class constructor.
@@ -169,12 +170,10 @@ protected function init(): void
169170 'endMemory ' => 0 ,
170171 ];
171172
172- if (!$ this ->errorHandler ) {
173- $ this ->errorHandler = new ErrorHandler ([
174- 'rootPath ' => $ this ->config ['rootPath ' ],
175- 'hideRootPath ' => (bool )$ this ->config ['hideRootPath ' ],
176- ]);
177- }
173+ $ this ->errorHandler = new ErrorHandler ([
174+ 'rootPath ' => $ this ->config ['rootPath ' ],
175+ 'hideRootPath ' => (bool )$ this ->config ['hideRootPath ' ],
176+ ]);
178177
179178 $ this ->registerErrorHandle ();
180179
@@ -288,10 +287,10 @@ protected function beforeRun(): bool
288287 *
289288 * @param bool $exit
290289 *
291- * @return int| mixed
290+ * @return mixed
292291 * @throws InvalidArgumentException
293292 */
294- public function run (bool $ exit = true )
293+ public function run (bool $ exit = true ): mixed
295294 {
296295 try {
297296 // init
@@ -334,6 +333,7 @@ protected function afterRun(): void
334333 /**
335334 * @param int $code
336335 */
336+ #[NoReturn]
337337 public function stop (int $ code = 0 ): void
338338 {
339339 // call 'onAppStop' event, if it is registered.
@@ -355,9 +355,9 @@ public function stop(int $code = 0): void
355355 /**
356356 * @param array $args
357357 *
358- * @return int| mixed
358+ * @return mixed
359359 */
360- public function runWithArgs (array $ args )
360+ public function runWithArgs (array $ args ): mixed
361361 {
362362 $ this ->input ->setFlags ($ args );
363363 return $ this ->run (false );
@@ -382,9 +382,9 @@ public function runWithIO(InputInterface $input, OutputInterface $output): void
382382 * @param InputInterface $input
383383 * @param OutputInterface $output
384384 *
385- * @return int| mixed
385+ * @return mixed
386386 */
387- public function subRun (string $ command , InputInterface $ input , OutputInterface $ output )
387+ public function subRun (string $ command , InputInterface $ input , OutputInterface $ output ): mixed
388388 {
389389 $ app = $ this ->copy ();
390390 $ app ->setInput ($ input );
@@ -449,6 +449,7 @@ protected function registerErrorHandle(): void
449449 *
450450 * @throws InvalidArgumentException
451451 */
452+ #[NoReturn]
452453 public function handleError (int $ num , string $ str , string $ file , int $ line ): void
453454 {
454455 $ this ->handleException (new ErrorException ($ str , 0 , $ num , $ file , $ line ));
@@ -591,11 +592,11 @@ protected function startInteractiveShell(): void
591592
592593 /**
593594 * @param string $name
594- * @param string| array $aliases
595+ * @param array|string $aliases
595596 *
596597 * @return $this
597598 */
598- public function addAliases (string $ name , $ aliases ): self
599+ public function addAliases (string $ name , array | string $ aliases ): self
599600 {
600601 if ($ name && $ aliases ) {
601602 $ this ->router ->setAlias ($ name , $ aliases , true );
@@ -768,12 +769,12 @@ public function getArrayParam(string $name, array $default = []): array
768769 /**
769770 * Get config param value
770771 *
771- * @param string $name
772- * @param null|string| mixed $default
772+ * @param string $name
773+ * @param mixed|null $default
773774 *
774- * @return array|string
775+ * @return mixed
775776 */
776- public function getParam (string $ name , $ default = null )
777+ public function getParam (string $ name , mixed $ default = null ): mixed
777778 {
778779 return $ this ->config [$ name ] ?? $ default ;
779780 }
0 commit comments