Skip to content

Commit d51b7ad

Browse files
committed
Fix progress bar
1 parent 7fdd9c4 commit d51b7ad

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Command/AnalyseCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
330330
throw new ShouldNotHappenException();
331331
}
332332

333+
if ($fix) {
334+
$inceptionResult->getErrorOutput()->writeLineFormatted('Analysing files...');
335+
}
336+
333337
try {
334338
$analysisResult = $application->analyse(
335339
$files,
@@ -512,7 +516,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
512516
}
513517

514518
$fixableErrorsCount = count($fixableErrors);
515-
if (count($fixableErrors) === 0) {
519+
if ($fixableErrorsCount === 0) {
516520
$inceptionResult->getStdOutput()->getStyle()->error('No fixable errors found');
517521
$exitCode = 1;
518522
} else {
@@ -531,18 +535,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
531535
$diffsByFile[$fixFile][] = $fixableError->getFixedErrorDiff();
532536
}
533537

538+
$inceptionResult->getErrorOutput()->writeLineFormatted('Fixing errors...');
539+
$errorOutput->getStyle()->progressStart($fixableErrorsCount);
540+
534541
$patcher = $container->getByType(Patcher::class);
535542
foreach ($diffsByFile as $file => $diffs) {
543+
$diffsCount = count($diffs);
536544
try {
537545
$finalFileContents = $patcher->applyDiffs($file, $diffs);
546+
$errorOutput->getStyle()->progressAdvance($diffsCount);
538547
} catch (FileChangedException | MergeConflictException) {
539-
$skippedCount += count($diffs);
548+
$skippedCount += $diffsCount;
549+
$errorOutput->getStyle()->progressAdvance($diffsCount);
540550
continue;
541551
}
542552

543553
FileWriter::write($file, $finalFileContents);
544554
}
545555

556+
$errorOutput->getStyle()->progressFinish();
557+
546558
if ($skippedCount > 0) {
547559
$inceptionResult->getStdOutput()->getStyle()->warning(sprintf(
548560
'%d %s fixed, %d %s skipped',

0 commit comments

Comments
 (0)