diff --git a/libraries/classes/Import.php b/libraries/classes/Import.php index b09e1e320d..d401defe02 100644 --- a/libraries/classes/Import.php +++ b/libraries/classes/Import.php @@ -587,6 +587,7 @@ class Import * * @return array Contains the precision, scale, and full size * representation of the given decimal cell + * @psalm-return array{int,int,string} */ public function getDecimalSize(string $cell): array { @@ -710,15 +711,19 @@ class Import * The last cumulative type was DECIMAL */ $size = $this->getDecimalSize($cell); + $m = $size[self::M]; + $d = $size[self::D]; $oldM = $this->getDecimalPrecision($lastCumulativeSize); $oldD = $this->getDecimalScale($lastCumulativeSize); /* New val if M or D is greater than current largest */ - if ($size[self::M] > $oldM || $size[self::D] > $oldD) { - /* Take the largest of both types */ - return (string) (($size[self::M] > $oldM ? $size[self::M] : $oldM) - . ',' . ($size[self::D] > $oldD ? $size[self::D] : $oldD)); + if ($m - $d > $oldM - $oldD || $d > $oldD) { + // Widen type to fit current cell + $newD = $oldD > $d ? $oldD : $d; + $newM = ($oldM - $oldD > $m - $d ? $oldM - $oldD : $m - $d) + $newD; + + return $newM . ',' . $newD; } return $lastCumulativeSize; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 58bd12e21c..27f5b0eb67 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20522,7 +20522,7 @@ parameters: - message: "#^Casting to string something that's already string\\.$#" - count: 4 + count: 3 path: libraries/classes/Import.php - @@ -20570,21 +20570,11 @@ parameters: count: 1 path: libraries/classes/Import.php - - - message: "#^Method PhpMyAdmin\\\\Import\\:\\:detectSize\\(\\) should return int\\|string but returns mixed\\.$#" - count: 3 - path: libraries/classes/Import.php - - message: "#^Method PhpMyAdmin\\\\Import\\:\\:executeQuery\\(\\) has parameter \\$sqlData with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Import.php - - - message: "#^Method PhpMyAdmin\\\\Import\\:\\:getDecimalSize\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: libraries/classes/Import.php - - message: "#^Method PhpMyAdmin\\\\Import\\:\\:getLocalFiles\\(\\) has parameter \\$importList with no value type specified in iterable type array\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5950f31017..a55969acd5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7838,14 +7838,11 @@ $sql_query $table - - string|int - getExtension getProperties - + $complete_query $display_query $executed_queries @@ -7855,9 +7852,6 @@ $read_multiply $size $size - $size[self::D] - $size[self::D] > $oldD ? $size[self::D] : $oldD - $size[self::M] > $oldM ? $size[self::M] : $oldM $skip_queries $sqlData['valid_queries'] $sqlData['valid_queries'] @@ -7866,11 +7860,6 @@ $sql_query $timestamp - - $size[self::FULL] - $size[self::FULL] - $size[self::M] - $decPos strpos($lastCumulativeSize, ',') @@ -7890,7 +7879,7 @@ $additionalSql[$i] - + (string) $cell (string) $cell (string) $cell diff --git a/test/classes/ImportTest.php b/test/classes/ImportTest.php index 71cd8d06d9..b09ebc2d9e 100644 --- a/test/classes/ImportTest.php +++ b/test/classes/ImportTest.php @@ -455,6 +455,45 @@ class ImportTest extends AbstractTestCase return $data; } + /** + * Test for detectSize + * + * @param string|int $lastCumulativeSize Last cumulative column size + * @param int|null $lastCumulativeType Last cumulative column type (NONE or VARCHAR or DECIMAL or INT or BIGINT) + * @param int $currentCellType Type of the current cell (NONE or VARCHAR or DECIMAL or INT or BIGINT) + * @param string $cell The current cell + * + * @dataProvider provTestDetectSize + */ + public function testDetectSize( + string $expected, + $lastCumulativeSize, + ?int $lastCumulativeType, + int $currentCellType, + string $cell + ): void { + $actual = $this->import->detectSize($lastCumulativeSize, $lastCumulativeType, $currentCellType, $cell); + self::assertSame($expected, $actual); + } + + /** + * Data provider for testDetectSize + * + * @return array + */ + public function provTestDetectSize(): array + { + return [ + [ + '8,3', + '7,2', + Import::DECIMAL, + Import::DECIMAL, + '11.555', + ], + ]; + } + /** * Test for checkIfRollbackPossible */