From 9aa1eb46c1b12fada74dc0c529e93d1ccef22576 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 5 Jun 2021 22:03:01 +0200 Subject: [PATCH] Fix incompatible implicit float-to-int conversions Signed-off-by: Alexander M. Turek --- Helper/ProgressBar.php | 4 ++-- Helper/Table.php | 2 +- Tests/Helper/ProgressBarTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index 5049c7dae..1de9b7b3c 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -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) @@ -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) { diff --git a/Helper/Table.php b/Helper/Table.php index 329f24082..d51aee989 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -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 { diff --git a/Tests/Helper/ProgressBarTest.php b/Tests/Helper/ProgressBarTest.php index 2d32e1c3d..9fdaa570d 100644 --- a/Tests/Helper/ProgressBarTest.php +++ b/Tests/Helper/ProgressBarTest.php @@ -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();