Skip to content

Commit

Permalink
[DX] Show progress bar 100% on RectorConsoleOutputFormatter::report() (
Browse files Browse the repository at this point in the history
…#4516)

* [DX] Show progress bar 100% on RectorConsoleOutputFormatter::report()

* [DX] Show progress bar 100% on RectorConsoleOutputFormatter::report()
  • Loading branch information
samsonasik committed Jul 14, 2023
1 parent f056974 commit d41685d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/ChangesReporting/Output/ConsoleOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ public function __construct(

public function report(ProcessResult $processResult, Configuration $configuration): void
{
$errors = $processResult->getErrors();

// only show 100% when no errors
if ($errors === [] && $configuration->shouldShowProgressBar()) {
$this->rectorOutputStyle->progressFinish();
}

// show diff after progress bar
if ($configuration->shouldShowDiffs()) {
$this->reportFileDiffs($processResult->getFileDiffs());
}

$this->reportErrors($processResult->getErrors());

if ($processResult->getErrors() !== []) {
if ($errors !== []) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Console/Output/RectorOutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function progressAdvance(int $step = 1): void
$this->rectorConsoleOutputStyle->progressAdvance($step);
}

public function progressFinish(): void
{
$this->rectorConsoleOutputStyle->progressFinish();
}

public function error(string $message): void
{
$this->rectorConsoleOutputStyle->error($message);
Expand Down
11 changes: 11 additions & 0 deletions src/Console/Style/RectorConsoleOutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@ private function getProgressBar(): ProgressBar
{
return $this->progressBar ?? throw new RuntimeException('The ProgressBar is not started.');
}

public function progressFinish(): void
{
// hide progress bar in tests
if (defined('PHPUNIT_COMPOSER_INSTALL')) {
return;
}

$progressBar = $this->getProgressBar();
$progressBar->finish();
}
}
2 changes: 2 additions & 0 deletions src/Contract/Console/OutputStyleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public function setVerbosity(int $level): void;
public function progressStart(int $fileCount): void;

public function progressAdvance(int $step = 1): void;

public function progressFinish(): void;
}

0 comments on commit d41685d

Please sign in to comment.