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
-------
fc7447681c
Fix incompatible implicit float-to-int conversions
This commit is contained in:
commit
5854a820db
@ -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)
|
||||
{
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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]}";
|
||||
|
Reference in New Issue
Block a user