Skip to content

Commit

Permalink
Progress bar - do not output too many lines in CI environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 20, 2020
1 parent 4b18031 commit 117736f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"nette/schema": "^1.0",
"nette/utils": "^3.0",
"nikic/php-parser": "^4.3.0",
"ondram/ci-detector": "^3.1",
"ondrejmirtes/better-reflection": "^3.5.5",
"phpstan/phpdoc-parser": "^0.4.2",
"symfony/console": "^4.3",
Expand Down
21 changes: 18 additions & 3 deletions src/Command/ErrorsConsoleStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Command;

use OndraM\CiDetector\CiDetector;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -17,12 +18,25 @@ class ErrorsConsoleStyle extends \Symfony\Component\Console\Style\SymfonyStyle
/** @var \Symfony\Component\Console\Helper\ProgressBar */
private $progressBar;

/** @var bool|null */
private $isCiDetected;

public function __construct(InputInterface $input, OutputInterface $output)
{
parent::__construct($input, $output);
$this->showProgress = $input->hasOption(self::OPTION_NO_PROGRESS) && !(bool) $input->getOption(self::OPTION_NO_PROGRESS);
}

private function isCiDetected(): bool
{
if ($this->isCiDetected === null) {
$ciDetector = new CiDetector();
$this->isCiDetected = $ciDetector->isCiDetected();
}

return $this->isCiDetected;
}

/**
* @param string[] $headers
* @param string[][] $rows
Expand Down Expand Up @@ -68,7 +82,7 @@ public function table(array $headers, array $rows): void
public function createProgressBar($max = 0): ProgressBar
{
$this->progressBar = parent::createProgressBar($max);
$this->progressBar->setOverwrite(true);
$this->progressBar->setOverwrite(!$this->isCiDetected());
return $this->progressBar;
}

Expand All @@ -93,7 +107,8 @@ public function progressAdvance($step = 1): void
if (!$this->showProgress) {
return;
}
if ($step > 0) {

if (!$this->isCiDetected() && $step > 0) {
$stepTime = (time() - $this->progressBar->getStartTime()) / $step;
if ($stepTime > 0 && $stepTime < 1) {
$this->progressBar->setRedrawFrequency((int) (1 / $stepTime));
Expand All @@ -102,7 +117,7 @@ public function progressAdvance($step = 1): void
}
}

$this->progressBar->setProgress($this->progressBar->getProgress() + $step);
parent::progressAdvance($step);
}

public function progressFinish(): void
Expand Down

0 comments on commit 117736f

Please sign in to comment.