Fix division by zero in ConsoleProgressBar

The rendering of the progress bar was causing a division by zero error when the maximum value was set to 0. This change adds a condition to check if the maximum value is not 0 before calculating the number of hashes and the percentage done in the progress bar. This avoids the division by zero error and makes the progress bar rendering more robust. The CHANGELOG.md file has also been updated to reflect this bug fix.
This commit is contained in:
Netkas 2023-10-22 19:26:16 -04:00
parent 698d2e7a1f
commit bcc6f45eb4
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 10 additions and 3 deletions

View file

@ -13,6 +13,7 @@ This update introduces minor bug fixes.
### Fixed
- Improve build efficiency by preventing duplicate merges
- Updated file tracking in Runtime class
- Fixed division by zero in ConsoleProgressBar
## [2.0.3] - 2023-10-17

View file

@ -368,10 +368,16 @@
*/
private function renderProgressBar(): string
{
$hashes_count = round($this->progress_width * $this->value / $this->max_value);
$dashes_count = $this->progress_width - $hashes_count;
$percent_done = round($this->value * 100 / $this->max_value);
$hashes_count = 0;
$percent_done = 0;
if($this->max_value !== 0)
{
$hashes_count = round($this->progress_width * $this->value / $this->max_value);
$percent_done = round($this->value * 100 / $this->max_value);
}
$dashes_count = $this->progress_width - $hashes_count;
return ' [' . str_repeat('#', $hashes_count) . str_repeat('-', $dashes_count) . ']' . sprintf('%4s', $percent_done) . '%';
}