Skip to content

Commit 02d37f6

Browse files
authored
Merge pull request #53 from adhocore/develop
refactor(interactor): reduce complexity in prompt
2 parents 6ae66b0 + dd008af commit 02d37f6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/IO/Interactor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,18 @@ public function prompt(string $text, $default = null, callable $fn = null, int $
282282
{
283283
$error = 'Invalid value. Please try again!';
284284
$hidden = \func_get_args()[4] ?? false;
285-
$readFn = $hidden ? 'readHidden' : 'read';
285+
$readFn = ['read', 'readHidden'][(int) $hidden];
286286

287287
$this->writer->yellow($text)->comment(null !== $default ? " [$default]: " : ': ');
288288

289289
try {
290290
$input = $this->reader->{$readFn}($default, $fn);
291-
} catch (\Exception $e) {
291+
} catch (\Throwable $e) {
292+
$input = '';
292293
$error = $e->getMessage();
293294
}
294295

295-
if ($retry > 0 && (isset($e) || \strlen($input ?? '') === 0)) {
296+
if ($retry > 0 && $input === '') {
296297
$this->writer->bgRed($error, true);
297298

298299
return $this->prompt($text, $default, $fn, $retry - 1, $hidden);

0 commit comments

Comments
 (0)