Fix incompatible implicit float-to-int conversions

Signed-off-by: Alexander M. Turek <me@derrabus.de>
This commit is contained in:
Alexander M. Turek 2021-06-05 22:03:01 +02:00
parent 6c180f271b
commit fc7447681c
7 changed files with 17 additions and 17 deletions

View File

@ -193,7 +193,7 @@ final class ProgressBar
public function getBarOffset(): int 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) public function setBarWidth(int $size)
@ -249,7 +249,7 @@ final class ProgressBar
/** /**
* Sets the redraw frequency. * 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) public function setRedrawFrequency(?int $freq)
{ {

View File

@ -454,7 +454,7 @@ class Table
$formattedTitle = sprintf($titleFormat, Helper::substr($title, 0, $limit - $formatLength - 3).'...'); $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)) { if (false === mb_detect_encoding($markup, null, true)) {
$markup = substr_replace($markup, $formattedTitle, $titleStart, $titleLength); $markup = substr_replace($markup, $formattedTitle, $titleStart, $titleLength);
} else { } else {

View File

@ -535,7 +535,7 @@ And, as in uffish thought he stood, The Jabberwock, with eyes of flame, Came whi
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven() public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
{ {
$bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0);
$bar->setRedrawFrequency(0.9); $bar->setRedrawFrequency(0);
$bar->start(); $bar->start();
$bar->advance(); $bar->advance();

View File

@ -72,7 +72,7 @@ class PdoStoreTest extends AbstractStoreTest
{ {
$this->expectException(InvalidTtlException::class); $this->expectException(InvalidTtlException::class);
return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0.1); return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0);
} }
/** /**

View File

@ -42,7 +42,7 @@ class CliDescriptor implements DumpDescriptorInterface
$io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output); $io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output);
$this->dumper->setColors($output->isDecorated()); $this->dumper->setColors($output->isDecorated());
$rows = [['date', date('r', $context['timestamp'])]]; $rows = [['date', date('r', (int) $context['timestamp'])]];
$lastIdentifier = $this->lastIdentifier; $lastIdentifier = $this->lastIdentifier;
$this->lastIdentifier = $clientId; $this->lastIdentifier = $clientId;

View File

@ -94,7 +94,7 @@ HTML
private function extractDate(array $context, string $format = 'r'): string 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 private function renderTags(array $tags): string

View File

@ -523,7 +523,7 @@ class InlineTest extends TestCase
/** /**
* @dataProvider getTimestampTests * @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)); $this->assertSame(gmmktime($hour, $minute, $second, $month, $day, $year), Inline::parse($yaml));
} }
@ -531,37 +531,37 @@ class InlineTest extends TestCase
/** /**
* @dataProvider getTimestampTests * @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 = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC')); $expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day); $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); $date = Inline::parse($yaml, Yaml::PARSE_DATETIME);
$this->assertEquals($expected, $date); $this->assertEquals($expected, $date);
$this->assertSame($timezone, $date->format('O')); $this->assertSame($timezone, $date->format('O'));
} }
public function getTimestampTests() public function getTimestampTests(): array
{ {
return [ return [
'canonical' => ['2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1, '+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.1, '-0500'], '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.1, '-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, '+0000'], 'date' => ['2001-12-15', 2001, 12, 15, 0, 0, 0, 0, '+0000'],
]; ];
} }
/** /**
* @dataProvider getTimestampTests * @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 = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC')); $expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day); $expected->setDate($year, $month, $day);
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second)); $expected->setTime($hour, $minute, $second, $microsecond);
$expectedNested = ['nested' => [$expected]]; $expectedNested = ['nested' => [$expected]];
$yamlNested = "{nested: [$yaml]}"; $yamlNested = "{nested: [$yaml]}";