Skip to content

Commit 7f49c84

Browse files
LukeTowersnicolas-grekas
authored andcommitted
[HttpFoundation] Drop int return type from parseFilesize()
1 parent c4509bb commit 7f49c84

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

File/UploadedFile.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function move($directory, $name = null)
239239
/**
240240
* Returns the maximum size of an uploaded file as configured in php.ini.
241241
*
242-
* @return int The maximum size of an uploaded file in bytes
242+
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
243243
*/
244244
public static function getMaxFilesize()
245245
{
@@ -251,8 +251,10 @@ public static function getMaxFilesize()
251251

252252
/**
253253
* Returns the given size from an ini value in bytes.
254+
*
255+
* @return int|float Returns float if size > PHP_INT_MAX
254256
*/
255-
private static function parseFilesize($size): int
257+
private static function parseFilesize($size)
256258
{
257259
if ('' === $size) {
258260
return 0;

Tests/File/UploadedFileTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException;
1616
use Symfony\Component\HttpFoundation\File\Exception\ExtensionFileException;
1717
use Symfony\Component\HttpFoundation\File\Exception\FileException;
18+
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
1819
use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException;
1920
use Symfony\Component\HttpFoundation\File\Exception\IniSizeFileException;
2021
use Symfony\Component\HttpFoundation\File\Exception\NoFileException;
@@ -33,7 +34,7 @@ protected function setUp(): void
3334

3435
public function testConstructWhenFileNotExists()
3536
{
36-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
37+
$this->expectException(FileNotFoundException::class);
3738

3839
new UploadedFile(
3940
__DIR__.'/Fixtures/not_here',
@@ -358,13 +359,16 @@ public function testGetMaxFilesize()
358359
{
359360
$size = UploadedFile::getMaxFilesize();
360361

361-
$this->assertIsInt($size);
362+
if ($size > \PHP_INT_MAX) {
363+
$this->assertIsFloat($size);
364+
} else {
365+
$this->assertIsInt($size);
366+
}
367+
362368
$this->assertGreaterThan(0, $size);
363369

364370
if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) {
365371
$this->assertSame(\PHP_INT_MAX, $size);
366-
} else {
367-
$this->assertLessThan(\PHP_INT_MAX, $size);
368372
}
369373
}
370374
}

0 commit comments

Comments
 (0)