1919use Symfony \Component \Console \Command \Command as SymfonyCommand ;
2020use Symfony \Component \Console \Formatter \OutputFormatterStyle ;
2121use Symfony \Component \Console \Helper \Table ;
22+ use Symfony \Component \Console \Helper \TableStyle ;
2223use Symfony \Component \Console \Input \ArrayInput ;
2324use Symfony \Component \Console \Input \InputInterface ;
2425use Symfony \Component \Console \Output \OutputInterface ;
@@ -32,58 +33,39 @@ abstract class Command extends SymfonyCommand
3233
3334 /**
3435 * The name of the command.
35- *
36- * @var string
3736 */
38- protected $ name ;
37+ protected ? string $ name = null ;
3938
40- /**
41- * @var InputInterface
42- */
43- protected $ input ;
39+ protected ?InputInterface $ input = null ;
4440
4541 /**
46- * @var SymfonyStyle
42+ * @var null| SymfonyStyle
4743 */
48- protected $ output ;
44+ protected ? OutputInterface $ output = null ;
4945
5046 /**
5147 * The default verbosity of output commands.
52- *
53- * @var int
5448 */
55- protected $ verbosity = OutputInterface::VERBOSITY_NORMAL ;
49+ protected int $ verbosity = OutputInterface::VERBOSITY_NORMAL ;
5650
5751 /**
5852 * Execution in a coroutine environment.
59- *
60- * @var bool
6153 */
62- protected $ coroutine = true ;
54+ protected bool $ coroutine = true ;
6355
64- /**
65- * @var null|EventDispatcherInterface
66- */
67- protected $ eventDispatcher ;
56+ protected ?EventDispatcherInterface $ eventDispatcher = null ;
6857
69- /**
70- * @var int
71- */
72- protected $ hookFlags ;
58+ protected int $ hookFlags = -1 ;
7359
7460 /**
7561 * The name and signature of the command.
76- *
77- * @var null|string
7862 */
79- protected $ signature ;
63+ protected ? string $ signature = null ;
8064
8165 /**
82- * The mapping between human readable verbosity levels and Symfony's OutputInterface.
83- *
84- * @var array
66+ * The mapping between human-readable verbosity levels and Symfony's OutputInterface.
8567 */
86- protected $ verbosityMap
68+ protected array $ verbosityMap
8769 = [
8870 'v ' => OutputInterface::VERBOSITY_VERBOSE ,
8971 'vv ' => OutputInterface::VERBOSITY_VERY_VERBOSE ,
@@ -94,25 +76,21 @@ abstract class Command extends SymfonyCommand
9476
9577 /**
9678 * The exit code of the command.
97- *
98- * @var int
9979 */
100- protected $ exitCode = 0 ;
80+ protected int $ exitCode = 0 ;
10181
10282 public function __construct (string $ name = null )
10383 {
104- if (! $ name && $ this ->name ) {
105- $ name = $ this ->name ;
106- }
84+ $ this ->name = $ name ?? $ this ->name ;
10785
108- if (! is_int ( $ this ->hookFlags ) ) {
86+ if ($ this ->hookFlags < 0 ) {
10987 $ this ->hookFlags = swoole_hook_flags ();
11088 }
11189
11290 if (isset ($ this ->signature )) {
11391 $ this ->configureUsingFluentDefinition ();
11492 } else {
115- parent ::__construct ($ name );
93+ parent ::__construct ($ this -> name );
11694 }
11795
11896 $ this ->addEnableDispatcherOption ();
@@ -138,28 +116,26 @@ public function confirm(string $question, bool $default = false): bool
138116
139117 /**
140118 * Prompt the user for input.
141- *
142- * @param null|mixed $default
143119 */
144- public function ask (string $ question , $ default = null )
120+ public function ask (string $ question , string $ default = null )
145121 {
146122 return $ this ->output ->ask ($ question , $ default );
147123 }
148124
149125 /**
150- * Prompt the user for input with auto completion.
126+ * Prompt the user for input with auto- completion.
151127 *
152- * @param null|mixed $default
128+ * @param null|bool|float|int|string $default
153129 */
154130 public function anticipate (string $ question , array $ choices , $ default = null )
155131 {
156132 return $ this ->askWithCompletion ($ question , $ choices , $ default );
157133 }
158134
159135 /**
160- * Prompt the user for input with auto completion.
136+ * Prompt the user for input with auto- completion.
161137 *
162- * @param null|mixed $default
138+ * @param null|bool|float|int|string $default
163139 */
164140 public function askWithCompletion (string $ question , array $ choices , $ default = null )
165141 {
@@ -184,7 +160,7 @@ public function secret(string $question, bool $fallback = true)
184160
185161 /**
186162 * Give the user a multiple choice from an array of answers.
187- * @param null| mixed $default
163+ * @param mixed $default
188164 */
189165 public function choiceMultiple (
190166 string $ question ,
@@ -202,7 +178,7 @@ public function choiceMultiple(
202178 /**
203179 * Give the user a single choice from an array of answers.
204180 *
205- * @param null| mixed $default
181+ * @param mixed $default
206182 */
207183 public function choice (
208184 string $ question ,
@@ -215,19 +191,16 @@ public function choice(
215191
216192 /**
217193 * Format input to textual table.
218- *
219- * @param mixed $rows
220- * @param mixed $tableStyle
221194 */
222- public function table (array $ headers , $ rows , $ tableStyle = 'default ' , array $ columnStyles = []): void
195+ public function table (array $ headers , array | Arrayable $ rows , TableStyle | string $ tableStyle = 'default ' , array $ columnStyles = []): void
223196 {
224197 $ table = new Table ($ this ->output );
225198
226199 if ($ rows instanceof Arrayable) {
227200 $ rows = $ rows ->toArray ();
228201 }
229202
230- $ table ->setHeaders (( array ) $ headers )->setRows ($ rows )->setStyle ($ tableStyle );
203+ $ table ->setHeaders ($ headers )->setRows ($ rows )->setStyle ($ tableStyle );
231204
232205 foreach ($ columnStyles as $ columnIndex => $ columnStyle ) {
233206 $ table ->setColumnStyle ($ columnIndex , $ columnStyle );
@@ -375,7 +348,7 @@ protected function createInputFromArguments(array $arguments): ArrayInput
375348 }
376349
377350 /**
378- * Get all of the context passed to the command.
351+ * Get all the context passed to the command.
379352 */
380353 protected function context (): array
381354 {
@@ -395,9 +368,9 @@ protected function context(): array
395368 */
396369 protected function specifyParameters (): void
397370 {
398- // We will loop through all of the arguments and options for the command and
371+ // We will loop through all the arguments and options for the command and
399372 // set them all on the base command instance. This specifies what can get
400- // passed into these commands as "parameters" to control the execution.
373+ // past into these commands as "parameters" to control the execution.
401374 if (method_exists ($ this , 'getArguments ' )) {
402375 foreach ($ this ->getArguments () ?? [] as $ arguments ) {
403376 call_user_func_array ([$ this , 'addArgument ' ], $ arguments );
0 commit comments