Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cbadd8

Browse files
minor #53661 [Console] Remove needless state from QuestionHelper (nicolas-grekas)
This PR was merged into the 7.1 branch. Discussion ---------- [Console] Remove needless state from `QuestionHelper` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Commits ------- d41a685 [Console] Remove needless state from QuestionHelper
2 parents d621936 + d41a685 commit 3cbadd8

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
*/
3535
class QuestionHelper extends Helper
3636
{
37-
/**
38-
* @var resource|null
39-
*/
40-
private $inputStream;
41-
4237
private static bool $stty = true;
4338
private static bool $stdinIsInteractive;
4439

@@ -59,16 +54,15 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
5954
return $this->getDefaultAnswer($question);
6055
}
6156

62-
if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
63-
$this->inputStream = $stream;
64-
}
57+
$inputStream = $input instanceof StreamableInputInterface ? $input->getStream() : null;
58+
$inputStream ??= STDIN;
6559

6660
try {
6761
if (!$question->getValidator()) {
68-
return $this->doAsk($output, $question);
62+
return $this->doAsk($inputStream, $output, $question);
6963
}
7064

71-
$interviewer = fn () => $this->doAsk($output, $question);
65+
$interviewer = fn () => $this->doAsk($inputStream, $output, $question);
7266

7367
return $this->validateAttempts($interviewer, $output, $question);
7468
} catch (MissingInputException $exception) {
@@ -98,13 +92,14 @@ public static function disableStty(): void
9892
/**
9993
* Asks the question to the user.
10094
*
95+
* @param resource $inputStream
96+
*
10197
* @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden
10298
*/
103-
private function doAsk(OutputInterface $output, Question $question): mixed
99+
private function doAsk($inputStream, OutputInterface $output, Question $question): mixed
104100
{
105101
$this->writePrompt($output, $question);
106102

107-
$inputStream = $this->inputStream ?: \STDIN;
108103
$autocomplete = $question->getAutocompleterCallback();
109104

110105
if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {

0 commit comments

Comments
 (0)