Skip to content

Commit 02096d4

Browse files
committed
feat: require explicit --stdin flag for stdin input
1 parent 6e42c83 commit 02096d4

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

app/Commands/DefaultCommand.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected function configure()
5151
new InputOption('cache-file', '', InputArgument::OPTIONAL, 'The path to the cache file'),
5252
new InputOption('parallel', 'p', InputOption::VALUE_NONE, 'Runs the linter in parallel (Experimental)'),
5353
new InputOption('max-processes', null, InputOption::VALUE_REQUIRED, 'The number of processes to spawn when using parallel execution'),
54+
new InputOption('stdin', null, InputOption::VALUE_NONE, 'Read and format code from standard input'),
5455
],
5556
);
5657
}
@@ -108,14 +109,6 @@ protected function fixStdinInput(FixCode $fixCode): int
108109
*/
109110
protected function hasStdinInput(): bool
110111
{
111-
if ($this->option('test') || $this->option('bail') || $this->option('repair')) {
112-
return false;
113-
}
114-
115-
if (! is_resource(STDIN) || stream_isatty(STDIN)) {
116-
return false;
117-
}
118-
119-
return ! stream_get_meta_data(STDIN)['eof'];
112+
return $this->option('stdin');
120113
}
121114
}

tests/Feature/StdinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Support\Facades\Process;
44

55
it('formats code from stdin', function (string $input, ?string $expected) {
6-
$result = Process::input($input)->run('php pint app/Test.php')->throw();
6+
$result = Process::input($input)->run('php pint app/Test.php --stdin')->throw();
77

88
expect($result)
99
->output()->toBe($expected ?? $input)

0 commit comments

Comments
 (0)