ProcessCommand: move file counting to ProcessCommandRepoter - ommits reference and unnecessary counting

This commit is contained in:
TomasVotruba 2018-01-06 21:10:35 +01:00
parent 864e20b57b
commit 9c15aa4882
2 changed files with 7 additions and 5 deletions

View File

@ -163,10 +163,10 @@ final class ProcessCommand extends Command
$this->consoleStyle->title(sprintf('Processing %d file%s', $totalFiles, $totalFiles === 1 ? '' : 's'));
$this->consoleStyle->progressStart($totalFiles);
$i = 0;
foreach ($fileInfos as $fileInfo) {
try {
$this->processFile($fileInfo, $i);
$this->processFile($fileInfo);
} catch (Throwable $throwable) {
$this->consoleStyle->newLine();
throw new FileProcessingException(
@ -176,13 +176,14 @@ final class ProcessCommand extends Command
);
}
$this->consoleStyle->progressAdvance();
}
$this->consoleStyle->newLine(2);
}
private function processFile(SplFileInfo $fileInfo, int &$i): void
private function processFile(SplFileInfo $fileInfo): void
{
$oldContent = $fileInfo->getContents();
@ -190,7 +191,7 @@ final class ProcessCommand extends Command
$newContent = $this->fileProcessor->processFileToString($fileInfo);
if ($newContent !== $oldContent) {
$this->diffFiles[] = [
'file' => sprintf('<options=bold>%d) %s</>', ++$i, $fileInfo->getPathname()),
'file' => $fileInfo->getPathname(),
'diff' => $this->differAndFormatter->diffAndFormat($oldContent, $newContent),
];
}

View File

@ -63,8 +63,9 @@ final class ProcessCommandReporter
count($diffFiles) === 1 ? '' : 's'
));
$i = 0;
foreach ($diffFiles as $diffFile) {
$this->consoleStyle->writeln($diffFile['file']);
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $diffFile['file']));
$this->consoleStyle->newLine();
$this->consoleStyle->writeln($diffFile['diff']);
$this->consoleStyle->newLine();