File tree Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Original file line number Diff line number Diff line change @@ -327,29 +327,20 @@ public static function promptByMultipleKeys(string $text, array $options): array
327
327
$ input = static ::prompt ($ extraOutput ) ?: 0 ; // 0 is default
328
328
329
329
// validation
330
- // return the prompt again if $input contain(s) non-numeric charachter, except a comma.
331
330
while (true ) {
332
331
$ pattern = preg_match_all ('/^\d+(,\d+)*$/ ' , trim ($ input ));
333
- if (! $ pattern ) {
334
- static ::error ('Please select correctly. ' );
335
- CLI ::newLine ();
336
- $ input = static ::prompt ($ extraOutput ) ?: 0 ;
337
- } else {
338
- break ;
339
- }
340
- }
341
- // user enters a number that is not in the available options
342
- while (true ) {
332
+
343
333
// separate input by comma and convert all to an int[]
344
334
$ inputToArray = array_map (static fn ($ value ) => (int ) $ value , explode (', ' , $ input ));
345
335
// find max from key of $options
346
336
$ maxOptions = array_key_last ($ options );
347
337
// find max from input
348
338
$ maxInput = max ($ inputToArray );
349
339
350
- // if max from $options less than max from input
340
+ // return the prompt again if $input contain(s) non-numeric charachter, except a comma.
341
+ // And if max from $options less than max from input
351
342
// it is mean user tried to access null value in $options
352
- if ($ maxOptions < $ maxInput ) {
343
+ if (! $ pattern || $ maxOptions < $ maxInput ) {
353
344
static ::error ('Please select correctly. ' );
354
345
CLI ::newLine ();
355
346
$ input = static ::prompt ($ extraOutput ) ?: 0 ;
You can’t perform that action at this time.
0 commit comments