Skip to content

Commit 117736f

Browse files
committed
Progress bar - do not output too many lines in CI environment
1 parent 4b18031 commit 117736f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"nette/schema": "^1.0",
1616
"nette/utils": "^3.0",
1717
"nikic/php-parser": "^4.3.0",
18+
"ondram/ci-detector": "^3.1",
1819
"ondrejmirtes/better-reflection": "^3.5.5",
1920
"phpstan/phpdoc-parser": "^0.4.2",
2021
"symfony/console": "^4.3",

src/Command/ErrorsConsoleStyle.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Command;
44

5+
use OndraM\CiDetector\CiDetector;
56
use Symfony\Component\Console\Helper\ProgressBar;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
@@ -17,12 +18,25 @@ class ErrorsConsoleStyle extends \Symfony\Component\Console\Style\SymfonyStyle
1718
/** @var \Symfony\Component\Console\Helper\ProgressBar */
1819
private $progressBar;
1920

21+
/** @var bool|null */
22+
private $isCiDetected;
23+
2024
public function __construct(InputInterface $input, OutputInterface $output)
2125
{
2226
parent::__construct($input, $output);
2327
$this->showProgress = $input->hasOption(self::OPTION_NO_PROGRESS) && !(bool) $input->getOption(self::OPTION_NO_PROGRESS);
2428
}
2529

30+
private function isCiDetected(): bool
31+
{
32+
if ($this->isCiDetected === null) {
33+
$ciDetector = new CiDetector();
34+
$this->isCiDetected = $ciDetector->isCiDetected();
35+
}
36+
37+
return $this->isCiDetected;
38+
}
39+
2640
/**
2741
* @param string[] $headers
2842
* @param string[][] $rows
@@ -68,7 +82,7 @@ public function table(array $headers, array $rows): void
6882
public function createProgressBar($max = 0): ProgressBar
6983
{
7084
$this->progressBar = parent::createProgressBar($max);
71-
$this->progressBar->setOverwrite(true);
85+
$this->progressBar->setOverwrite(!$this->isCiDetected());
7286
return $this->progressBar;
7387
}
7488

@@ -93,7 +107,8 @@ public function progressAdvance($step = 1): void
93107
if (!$this->showProgress) {
94108
return;
95109
}
96-
if ($step > 0) {
110+
111+
if (!$this->isCiDetected() && $step > 0) {
97112
$stepTime = (time() - $this->progressBar->getStartTime()) / $step;
98113
if ($stepTime > 0 && $stepTime < 1) {
99114
$this->progressBar->setRedrawFrequency((int) (1 / $stepTime));
@@ -102,7 +117,7 @@ public function progressAdvance($step = 1): void
102117
}
103118
}
104119

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

108123
public function progressFinish(): void

0 commit comments

Comments
 (0)