8000 [HttpFoundation] Drop int return type from parseFilesize() · symfony/symfony@a1b31f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1b31f8

Browse files
LukeTowersnicolas-grekas
authored andcommitted
[HttpFoundation] Drop int return type from parseFilesize()
1 parent 732bd84 commit a1b31f8

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

.appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ install:
2626
- echo memory_limit=-1 >> php.ini-min
2727
- echo serialize_precision=14 >> php.ini-min
2828
- echo max_execution_time=1200 >> php.ini-min
29+
- echo post_max_size=4G >> php.ini-min
30+
- echo upload_max_filesize=4G >> php.ini-min
2931
- echo date.timezone="America/Los_Angeles" >> php.ini-min
3032
- echo extension_dir=ext >> php.ini-min
3133
- echo extension=php_xsl.dll >> php.ini-min

src/Symfony/Component/Form/Extension/Core/Type/FileType.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ private function getFileUploadError(int $errorCode)
178178
* Returns the maximum size of an uploaded file as configured in php.ini.
179179
*
180180
* This method should be kept in sync with Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize().
181+
*
182+
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
181183
*/
182-
private static function getMaxFilesize(): int
184+
private static function getMaxFilesize()
183185
{
184186
$iniMax = strtolower(ini_get('upload_max_filesize'));
185187

@@ -214,8 +216,10 @@ private static function getMaxFilesize(): int
214216
* (i.e. try "MB", then "kB", then "bytes").
215217
*
216218
* This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::factorizeSizes().
219+
*
220+
* @param int|float $limit
217221
*/
218-
private function factorizeSizes(int $size, int $limit)
222+
private function factorizeSizes(int $size, $limit)
219223
{
220224
$coef = self::MIB_BYTES;
221225
$coefFactor = self::KIB_BYTES;

src/Symfony/Component/HttpFoundation/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;

src/Symfony/Component/HttpFoundation/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
}

src/Symfony/Component/Validator/Constraints/FileValidator.php

Lines changed: 3 additions & 1 deletion
1E0A
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ private static function moreDecimalsThan(string $double, int $numberOfDecimals):
214214
/**
215215
* Convert the limit to the smallest possible number
216216
* (i.e. try "MB", then "kB", then "bytes").
217+
*
218+
* @param int|float $limit
217219
*/
218-
private function factorizeSizes(int $size, int $limit, bool $binaryFormat): array
220+
private function factorizeSizes(int $size, $limit, bool $binaryFormat): array
219221
{
220222
if ($binaryFormat) {
221223
$coef = self::MIB_BYTES;

src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,12 @@ public function uploadedFileErrorProvider()
459459
[, $limit, $suffix] = $method->invokeArgs(new FileValidator(), [0, UploadedFile::getMaxFilesize(), false]);
460460

461461
// it correctly parses the maxSize option and not only uses simple string comparison
462-
// 1000M should be bigger than the ini value
462+
// 1000G should be bigger than the ini value
463463
$tests[] = [(string) \UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', [
464464
'{{ limit }}' => $limit,
465465
'{{ suffix }}' => $suffix,
466-
], '1000M'];
466+
], '1000G'];
467467

468-
// it correctly parses the maxSize option and not only uses simple string comparison
469-
// 1000M should be bigger than the ini value
470468
$tests[] = [(string) \UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', [
471469
'{{ limit }}' => '0.1',
472470
'{{ suffix }}' => 'MB',

0 commit comments

Comments
 (0)
0