Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpFoundation] Drop int return type from parseFilesize()
  • Loading branch information
LukeTowers authored and nicolas-grekas committed Jan 19, 2021
commit a1b31f840c9b989debee9fca7249f40779aebdf2
2 changes: 2 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ install:
- echo memory_limit=-1 >> php.ini-min
- echo serialize_precision=14 >> php.ini-min
- echo max_execution_time=1200 >> php.ini-min
- echo post_max_size=4G >> php.ini-min
- echo upload_max_filesize=4G >> php.ini-min
- echo date.timezone="America/Los_Angeles" >> php.ini-min
- echo extension_dir=ext >> php.ini-min
- echo extension=php_xsl.dll >> php.ini-min
Expand Down
8 changes: 6 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ private function getFileUploadError(int $errorCode)
* Returns the maximum size of an uploaded file as configured in php.ini.
*
* This method should be kept in sync with Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize().
*
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
*/
private static function getMaxFilesize(): int
private static function getMaxFilesize()
{
$iniMax = strtolower(ini_get('upload_max_filesize'));

Expand Down Expand Up @@ -214,8 +216,10 @@ private static function getMaxFilesize(): int
* (i.e. try "MB", then "kB", then "bytes").
*
* This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::factorizeSizes().
*
* @param int|float $limit
*/
private function factorizeSizes(int $size, int $limit)
private function factorizeSizes(int $size, $limit)
{
$coef = self::MIB_BYTES;
$coefFactor = self::KIB_BYTES;
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function move($directory, $name = null)
/**
* Returns the maximum size of an uploaded file as configured in php.ini.
*
* @return int The maximum size of an uploaded file in bytes
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
*/
public static function getMaxFilesize()
{
Expand All @@ -251,8 +251,10 @@ public static function getMaxFilesize()

/**
* Returns the given size from an ini value in bytes.
*
* @return int|float Returns float if size > PHP_INT_MAX
*/
private static function parseFilesize($size): int
private static function parseFilesize($size)
{
if ('' === $size) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException;
use Symfony\Component\HttpFoundation\File\Exception\ExtensionFileException;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException;
use Symfony\Component\HttpFoundation\File\Exception\IniSizeFileException;
use Symfony\Component\HttpFoundation\File\Exception\NoFileException;
Expand All @@ -33,7 +34,7 @@ protected function setUp(): void

public function testConstructWhenFileNotExists()
{
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
$this->expectException(FileNotFoundException::class);

new UploadedFile(
__DIR__.'/Fixtures/not_here',
Expand Down Expand Up @@ -358,13 +359,16 @@ public function testGetMaxFilesize()
{
$size = UploadedFile::getMaxFilesize();

$this->assertIsInt($size);
if ($size > \PHP_INT_MAX) {
$this->assertIsFloat($size);
} else {
$this->assertIsInt($size);
}

$this->assertGreaterThan(0, $size);

if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) {
$this->assertSame(\PHP_INT_MAX, $size);
} else {
$this->assertLessThan(\PHP_INT_MAX, $size);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ private static function moreDecimalsThan(string $double, int $numberOfDecimals):
/**
* Convert the limit to the smallest possible number
* (i.e. try "MB", then "kB", then "bytes").
*
* @param int|float $limit
*/
private function factorizeSizes(int $size, int $limit, bool $binaryFormat): array
private function factorizeSizes(int $size, $limit, bool $binaryFormat): array
{
if ($binaryFormat) {
$coef = self::MIB_BYTES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,12 @@ public function uploadedFileErrorProvider()
[, $limit, $suffix] = $method->invokeArgs(new FileValidator(), [0, UploadedFile::getMaxFilesize(), false]);

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

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