Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions app/Commands/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'];
}
}
67 changes: 0 additions & 67 deletions tests/Feature/StdinTest.php

This file was deleted.