From fc7447681cff7e5bcad42d3b349db34626c7910c 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 --- .../Component/Console/Helper/ProgressBar.php | 4 ++-- .../Component/Console/Helper/Table.php | 2 +- .../Console/Tests/Helper/ProgressBarTest.php | 2 +- .../Lock/Tests/Store/PdoStoreTest.php | 2 +- .../Command/Descriptor/CliDescriptor.php | 2 +- .../Command/Descriptor/HtmlDescriptor.php | 2 +- .../Component/Yaml/Tests/InlineTest.php | 20 +++++++++---------- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 5049c7dae0..1de9b7b3cf 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -193,7 +193,7 @@ final class ProgressBar 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 @@ final class ProgressBar /** * 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/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 329f240827..d51aee9890 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -454,7 +454,7 @@ class Table $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/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index 2d32e1c3d5..9fdaa570d3 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -535,7 +535,7 @@ And, as in uffish thought he stood, The Jabberwock, with eyes of flame, Came whi public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven() { $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); - $bar->setRedrawFrequency(0.9); + $bar->setRedrawFrequency(0); $bar->start(); $bar->advance(); diff --git a/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php index 2d7cf1035e..082f50aa75 100644 --- a/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php @@ -72,7 +72,7 @@ class PdoStoreTest extends AbstractStoreTest { $this->expectException(InvalidTtlException::class); - return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0.1); + return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0); } /** diff --git a/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php b/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php index dc77d03ecd..7d9ec0e7ee 100644 --- a/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php +++ b/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php @@ -42,7 +42,7 @@ class CliDescriptor implements DumpDescriptorInterface $io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output); $this->dumper->setColors($output->isDecorated()); - $rows = [['date', date('r', $context['timestamp'])]]; + $rows = [['date', date('r', (int) $context['timestamp'])]]; $lastIdentifier = $this->lastIdentifier; $this->lastIdentifier = $clientId; diff --git a/src/Symfony/Component/VarDumper/Command/Descriptor/HtmlDescriptor.php b/src/Symfony/Component/VarDumper/Command/Descriptor/HtmlDescriptor.php index 35a203b000..636b61828d 100644 --- a/src/Symfony/Component/VarDumper/Command/Descriptor/HtmlDescriptor.php +++ b/src/Symfony/Component/VarDumper/Command/Descriptor/HtmlDescriptor.php @@ -94,7 +94,7 @@ HTML private function extractDate(array $context, string $format = 'r'): string { - return date($format, $context['timestamp']); + return date($format, (int) $context['timestamp']); } private function renderTags(array $tags): string diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index b1f0206d54..b4b8520642 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -523,7 +523,7 @@ class InlineTest extends TestCase /** * @dataProvider getTimestampTests */ - public function testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month, $day, $hour, $minute, $second) + public function testParseTimestampAsUnixTimestampByDefault(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second) { $this->assertSame(gmmktime($hour, $minute, $second, $month, $day, $year), Inline::parse($yaml)); } @@ -531,37 +531,37 @@ class InlineTest extends TestCase /** * @dataProvider getTimestampTests */ - public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second, $timezone) + public function testParseTimestampAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone) { $expected = new \DateTime($yaml); $expected->setTimeZone(new \DateTimeZone('UTC')); $expected->setDate($year, $month, $day); - $expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second)); + $expected->setTime($hour, $minute, $second, $microsecond); $date = Inline::parse($yaml, Yaml::PARSE_DATETIME); $this->assertEquals($expected, $date); $this->assertSame($timezone, $date->format('O')); } - public function getTimestampTests() + public function getTimestampTests(): array { return [ - 'canonical' => ['2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1, '+0000'], - 'ISO-8601' => ['2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1, '-0500'], - 'spaced' => ['2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1, '-0500'], - 'date' => ['2001-12-15', 2001, 12, 15, 0, 0, 0, '+0000'], + 'canonical' => ['2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43, 100000, '+0000'], + 'ISO-8601' => ['2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43, 100000, '-0500'], + 'spaced' => ['2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43, 100000, '-0500'], + 'date' => ['2001-12-15', 2001, 12, 15, 0, 0, 0, 0, '+0000'], ]; } /** * @dataProvider getTimestampTests */ - public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second) + public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond) { $expected = new \DateTime($yaml); $expected->setTimeZone(new \DateTimeZone('UTC')); $expected->setDate($year, $month, $day); - $expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second)); + $expected->setTime($hour, $minute, $second, $microsecond); $expectedNested = ['nested' => [$expected]]; $yamlNested = "{nested: [$yaml]}";