22
33namespace PHPStan \Command ;
44
5+ use OndraM \CiDetector \CiDetector ;
56use Symfony \Component \Console \Helper \ProgressBar ;
67use Symfony \Component \Console \Input \InputInterface ;
78use 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