diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 75085c24a6..13c68c3b15 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -578,40 +578,24 @@ class InsertEdit /** * Retrieve the maximum upload file size - * - * @param string $pmaType column type - * @param int $biggestMaxFileSize biggest max file size for uploading - * - * @return mixed[] an html snippet and $biggest_max_file_size - * @psalm-return array{non-empty-string, int} */ - private function getMaxUploadSize(string $pmaType, int $biggestMaxFileSize): array + private function getMaxUploadSize(string $pmaType): string { // find maximum upload size, based on field type /** * @todo with functions this is not so easy, as you can basically * process any data with function like MD5 */ - $maxFieldSizes = [ + $maxFieldSize = match ($pmaType) { 'tinyblob' => 256, 'blob' => 65536, 'mediumblob' => 16777216, 'longblob' => 4294967296,// yeah, really - ]; + }; $thisFieldMaxSize = (int) $GLOBALS['config']->get('max_upload_size'); // from PHP max - if ($thisFieldMaxSize > $maxFieldSizes[$pmaType]) { - $thisFieldMaxSize = $maxFieldSizes[$pmaType]; - } - $htmlOutput = Util::getFormattedMaximumUploadSize($thisFieldMaxSize) . "\n"; - // do not generate here the MAX_FILE_SIZE, because we should - // put only one in the form to accommodate the biggest field - if ($thisFieldMaxSize > $biggestMaxFileSize) { - $biggestMaxFileSize = $thisFieldMaxSize; - } - - return [$htmlOutput, $biggestMaxFileSize]; + return Util::getFormattedMaximumUploadSize(min($thisFieldMaxSize, $maxFieldSize)) . "\n"; } /** @@ -2024,7 +2008,7 @@ class InsertEdit } if ($isUpload && $column['is_blob']) { - [$maxUploadSize] = $this->getMaxUploadSize($column['pma_type'], $biggestMaxFileSize); + $maxUploadSize = $this->getMaxUploadSize($column['pma_type']); } if (! empty($GLOBALS['cfg']['UploadDir'])) { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cf64841660..e6297f976f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4745,6 +4745,11 @@ parameters: count: 2 path: libraries/classes/InsertEdit.php + - + message: "#^Match expression does not handle remaining value\\: string$#" + count: 1 + path: libraries/classes/InsertEdit.php + - message: "#^Method PhpMyAdmin\\\\InsertEdit\\:\\:getFormParametersForInsertForm\\(\\) has parameter \\$whereClauses with no value type specified in iterable type array\\.$#" count: 1 diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 71a07c1f64..d0ea88561c 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -699,13 +699,10 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getMaxUploadSize', - [$pmaType, 256], + [$pmaType], ); - $this->assertEquals( - ["(Max: 256B)\n", 256], - $result, - ); + $this->assertEquals("(Max: 256B)\n", $result); // case 2 $GLOBALS['config']->set('max_upload_size', 250); @@ -714,13 +711,10 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getMaxUploadSize', - [$pmaType, 20], + [$pmaType], ); - $this->assertEquals( - ["(Max: 250B)\n", 250], - $result, - ); + $this->assertEquals("(Max: 250B)\n", $result); } /**