8000 minor #41555 Fix incompatible implicit float-to-int conversions (derr… · symfony/symfony@5854a82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5854a82

Browse files
minor #41555 Fix incompatible implicit float-to-int conversions (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- Fix incompatible implicit float-to-int conversions | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Part of #41552 | License | MIT | Doc PR | N/A PHP 8.1 is picky about implicit float-to-int casts if we lose precision because of that cast. This PR should fix all cases that bubbled up in our test suite. Commits ------- fc74476 Fix incompatible implicit float-to-int conversions
2 parents 6c180f2 + fc74476 commit 5854a82

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function getProgressPercent(): float
193193

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

199199
public function setBarWidth(int $size)
@@ -249,7 +249,7 @@ public function setFormat(string $format)
249249
/**
250250
* Sets the redraw frequency.
251251
*
252-
* @param int|float $freq The frequency in steps
252+
* @param int|null $freq The frequency in steps
253253
*/
254254
public function setRedrawFrequency(?int $freq)
255255
{

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $tit
454454
$formattedTitle = sprintf($titleFormat, Helper::substr($title, 0, $limit - $formatLength - 3).'...');
455455
}
456456

457-
$titleStart = ($markupLength - $titleLength) / 2;
457+
$titleStart = intdiv($markupLength - $titleLength, 2);
458458
if (false === mb_detect_encoding($markup, null, true)) {
459459
$markup = substr_replace($markup, $formattedTitle, $titleStart, $titleLength);
460460
} else {

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
535535
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
536536
{
537537
$bar = new ProgressBar($output = $this->getOutputStream(), 0, 0);
538-
$bar->setRedrawFrequency(0.9);
538+
$bar->setRedrawFrequency(0);
539539
$bar->start();
540540
$bar->advance();
541541

src/Symfony/Component/Lock/Tests/Store/PdoStoreTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testInvalidTtlConstruct()
7272
{
7373
$this->expectException(InvalidTtlException::class);
7474

75-
return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0.1);
75+
return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0);
7676
}
7777

7878
/**

src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function describe(OutputInterface $output, Data $data, array $context, in
4242
$io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output);
4343
$this->dumper->setColors($output->isDecorated());
4444

45-
$rows = [['date', date('r', $context['timestamp'])]];
45+
$rows = [['date', date('r', (int) $context['timestamp'])]];
4646
$lastIdentifier = $this->lastIdentifier;
4747
$this->lastIdentifier = $clientId;
4848

src/Symfony/Component/VarDumper/Command/Descriptor/HtmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function describe(OutputInterface $output, Data $data, array $context, in
9494

9595
private function extractDate(array $context, string $format = 'r'): string
9696
{
97-
return date($format, $context['timestamp']);
97+
return date($format, (int) $context['timestamp']);
9898
}
9999

100100
private function renderTags(array $tags): string

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -523,45 +523,45 @@ public function getTestsForDump()
523523
/**
524524
* @dataProvider getTimestampTests
525525
*/
526-
public function testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month, $day, $hour, $minute, $second)
526+
public function testParseTimestampAsUnixTimestampByDefault(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second)
527527
{
528528
$this->assertSame(gmmktime($hour, $minute, $second, $month, $day, $year), Inline::parse($yaml));
529529
}
530530

531531
/**
532532
* @dataProvider getTimestampTests
533533
*/
534-
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second, $timezone)
534+
public function testParseTimestampAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone)
535535
{
536536
$expected = new \DateTime($yaml);
537537
$expected->setTimeZone(new \DateTimeZone('UTC'));
538538
$expected->setDate($year, $month, $day);
539-
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
539+
$expected->setTime($hour, $minute, $second, $microsecond);
540540

541541
$date = Inline::parse($yaml, Yaml::PARSE_DATETIME);
542542
$this->assertEquals($expected, $date);
543543
$this->assertSame($timezone, $date->format('O'));
544544
}
545545

546-
public function getTimestampTests()
546+
public function getTimestampTests(): array
547547
{
548548
return [
549-
'canonical' => ['2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1, '+0000'],
550-
'ISO-8601' => ['2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1, '-0500'],
551-
'spaced' => ['2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1, '-0500'],
552-
'date' => ['2001-12-15', 2001, 12, 15, 0, 0, 0, '+0000'],
549+
'canonical' => ['2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43, 100000, '+0000'],
550+
'ISO-8601' => ['2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43, 100000, '-0500'],
551+
'spaced' => ['2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43, 100000, '-0500'],
552+
'date' => ['2001-12-15', 2001, 12, 15, 0, 0, 0, 0, '+0000'],
553553
];
554554
}
555555

556556
/**
557557
* @dataProvider getTimestampTests
558558
*/
559-
public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
559+
public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond)
560560
{
561561
$expected = new \DateTime($yaml);
562562
$expected->setTimeZone(new \DateTimeZone('UTC'));
563563
$expected->setDate($year, $month, $day);
564-
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
564+
$expected->setTime($hour, $minute, $second, $microsecond);
565565

566566
$expectedNested = ['nested' => [$expected]];
567567
$yamlNested = "{nested: [$yaml]}";

0 commit comments

Comments
 (0)
0