Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 19958fb

Browse filesBrowse files
peterjaapnicolas-grekas
authored andcommitted
[Console] Moved estimated & remaining calculation logic to separate get method
1 parent 1db7005 commit 19958fb
Copy full SHA for 19958fb

File tree

Expand file treeCollapse file tree

1 file changed

+21
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-15
lines changed

‎src/Symfony/Component/Console/Helper/ProgressBar.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/ProgressBar.php
+21-15Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,29 @@ public function getProgressPercent(): float
191191
return $this->percent;
192192
}
193193

194-
public function getBarOffset(): int
194+
public function getBarOffset(): float
195195
{
196196
return floor($this->max ? $this->percent * $this->barWidth : (null === $this->redrawFreq ? min(5, $this->barWidth / 15) * $this->writeCount : $this->step) % $this->barWidth);
197197
}
198198

199+
public function getEstimated(): float
200+
{
201+
if (!$this->step) {
202+
return 0;
203+
}
204+
205+
return round((time() - $this->startTime) / $this->step * $this->max);
206+
}
207+
208+
public function getRemaining(): float
209+
{
210+
if (!$this->step) {
211+
return 0;
212+
}
213+
214+
return round((time() - $this->startTime) / $this->step * ($this->max - $this->step));
215+
}
216+
199217
public function setBarWidth(int $size)
200218
{
201219
$this->barWidth = max(1, $size);
@@ -500,26 +518,14 @@ private static function initPlaceholderFormatters(): array
500518
throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
501519
}
502520

503-
if (!$bar->getProgress()) {
504-
$remaining = 0;
505-
} else {
506-
$remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
507-
}
508-
509-
return Helper::formatTime($remaining);
521+
return Helper::formatTime($bar->getRemaining());
510522
},
511523
'estimated' => function (self $bar) {
512524
if (!$bar->getMaxSteps()) {
513525
throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
514526
}
515527

516-
if (!$bar->getProgress()) {
517-
$estimated = 0;
518-
} else {
519-
$estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
520-
}
521-
522-
return Helper::formatTime($estimated);
528+
return Helper::formatTime($bar->getEstimated());
523529
},
524530
'memory' => function (self $bar) {
525531
return Helper::formatMemory(memory_get_usage(true));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.