mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 03:40:50 +00:00
[ProcessCommand] Fix --dry-run option conflict with progress bar
This commit is contained in:
parent
bddf758654
commit
35e4dfdf27
|
@ -72,6 +72,11 @@ final class ProcessCommand extends Command
|
|||
*/
|
||||
private $changedFiles = [];
|
||||
|
||||
/**
|
||||
* @var string[][]
|
||||
*/
|
||||
private $diffFiles = [];
|
||||
|
||||
public function __construct(
|
||||
FileProcessor $fileProcessor,
|
||||
RectorCollector $rectorCollector,
|
||||
|
@ -124,6 +129,10 @@ final class ProcessCommand extends Command
|
|||
|
||||
$this->processFiles($files);
|
||||
|
||||
if (count($this->diffFiles) > 0) {
|
||||
$this->processCommandReporter->reportDiffFiles($this->diffFiles);
|
||||
}
|
||||
|
||||
if (count($this->changedFiles) > 0) {
|
||||
$this->processCommandReporter->reportChangedFiles($this->changedFiles);
|
||||
}
|
||||
|
@ -154,7 +163,7 @@ final class ProcessCommand extends Command
|
|||
$this->consoleStyle->title(sprintf('Processing %d file%s', $totalFiles, $totalFiles === 1 ? '' : 's'));
|
||||
$this->consoleStyle->progressStart($totalFiles);
|
||||
|
||||
$i = 1;
|
||||
$i = 0;
|
||||
foreach ($fileInfos as $fileInfo) {
|
||||
try {
|
||||
$this->processFile($fileInfo, $i);
|
||||
|
@ -180,9 +189,10 @@ final class ProcessCommand extends Command
|
|||
$newContent = $this->fileProcessor->processFileToString($fileInfo);
|
||||
|
||||
if ($newContent !== $oldContent) {
|
||||
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', $i, $fileInfo->getPathname()));
|
||||
$this->consoleStyle->writeln($this->differAndFormatter->diffAndFormat($oldContent, $newContent));
|
||||
++$i;
|
||||
$this->diffFiles[] = [
|
||||
'file' => sprintf('<options=bold>%d) %s</>', ++$i, $fileInfo->getPathname()),
|
||||
'diff' => $this->differAndFormatter->diffAndFormat($oldContent, $newContent),
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$newContent = $this->fileProcessor->processFile($fileInfo);
|
||||
|
|
|
@ -52,6 +52,23 @@ final class ProcessCommandReporter
|
|||
$this->consoleStyle->listing($changedFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[][] $diffFiles
|
||||
*/
|
||||
public function reportDiffFiles(array $diffFiles): void
|
||||
{
|
||||
$this->consoleStyle->title(sprintf(
|
||||
'%d file%s with changes',
|
||||
count($diffFiles),
|
||||
count($diffFiles) === 1 ? '' : 's'
|
||||
));
|
||||
|
||||
foreach ($diffFiles as $diffFile) {
|
||||
$this->consoleStyle->writeln($diffFile['file']);
|
||||
$this->consoleStyle->writeln($diffFile['diff']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object[] $objects
|
||||
* @return object[]
|
||||
|
|
Loading…
Reference in New Issue
Block a user