diff --git a/app/Commands/DefaultCommand.php b/app/Commands/DefaultCommand.php index 3999e17d..c93598da 100644 --- a/app/Commands/DefaultCommand.php +++ b/app/Commands/DefaultCommand.php @@ -2,11 +2,9 @@ namespace App\Commands; -use App\Actions\FixCode; use LaravelZero\Framework\Commands\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; -use Throwable; class DefaultCommand extends Command { @@ -64,58 +62,8 @@ protected function configure() */ public function handle($fixCode, $elaborateSummary) { - if ($this->hasStdinInput()) { - return $this->fixStdinInput($fixCode); - } - [$totalFiles, $changes] = $fixCode->execute(); return $elaborateSummary->execute($totalFiles, $changes); } - - /** - * Fix the code sent to Pint on stdin and output to stdout. - */ - protected function fixStdinInput(FixCode $fixCode): int - { - $paths = $this->argument('path'); - - $contextPath = ! empty($paths) ? $paths[0] : 'stdin.php'; - $tempFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pint_stdin_'.uniqid().'.php'; - - $this->input->setArgument('path', [$tempFile]); - $this->input->setOption('format', 'json'); - - try { - file_put_contents($tempFile, stream_get_contents(STDIN)); - $fixCode->execute(); - fwrite(STDOUT, file_get_contents($tempFile)); - - return self::SUCCESS; - } catch (Throwable $e) { - fwrite(STDERR, "pint: error processing {$contextPath}: {$e->getMessage()}\n"); - - return self::FAILURE; - } finally { - if (file_exists($tempFile)) { - @unlink($tempFile); - } - } - } - - /** - * Determine if there is input available on stdin. - */ - protected function hasStdinInput(): bool - { - if ($this->option('test') || $this->option('bail') || $this->option('repair')) { - return false; - } - - if (! is_resource(STDIN) || stream_isatty(STDIN)) { - return false; - } - - return ! stream_get_meta_data(STDIN)['eof']; - } } diff --git a/tests/Feature/StdinTest.php b/tests/Feature/StdinTest.php deleted file mode 100644 index 140baad2..00000000 --- a/tests/Feature/StdinTest.php +++ /dev/null @@ -1,67 +0,0 @@ -run('php pint app/Test.php')->throw(); - - expect($result) - ->output()->toBe($expected ?? $input) - ->errorOutput()->toBe(''); -})->with([ - 'basic array and conditional' => [ - <<<'PHP' - [ - <<<'PHP' - "value"); - } - } - PHP, - <<<'PHP' - 'value']; - } - } - - PHP, - ], - 'already formatted code' => [ - <<<'PHP' - 'value']; - } - } - - PHP, - null, - ], -]);