Skip to content

Commit

Permalink
Fix incompatible implicit float-to-int conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <me@derrabus.de>
  • Loading branch information
derrabus committed Jun 6, 2021
1 parent e3d2125 commit 9aa1eb4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function getProgressPercent(): float

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

public function setBarWidth(int $size)
Expand Down Expand Up @@ -249,7 +249,7 @@ public function setFormat(string $format)
/**
* Sets the redraw frequency.
*
* @param int|float $freq The frequency in steps
* @param int|null $freq The frequency in steps
*/
public function setRedrawFrequency(?int $freq)
{
Expand Down
2 changes: 1 addition & 1 deletion Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $tit
$formattedTitle = sprintf($titleFormat, Helper::substr($title, 0, $limit - $formatLength - 3).'...');
}

$titleStart = ($markupLength - $titleLength) / 2;
$titleStart = intdiv($markupLength - $titleLength, 2);
if (false === mb_detect_encoding($markup, null, true)) {
$markup = substr_replace($markup, $formattedTitle, $titleStart, $titleLength);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Helper/ProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
{
$bar = new ProgressBar($output = $this->getOutputStream(), 0, 0);
$bar->setRedrawFrequency(0.9);
$bar->setRedrawFrequency(0);
$bar->start();
$bar->advance();

Expand Down

0 comments on commit 9aa1eb4

Please sign in to comment.