diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 8b71ebe163..9cbfd8b6cc 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -894,17 +894,12 @@ class InsertEdit /** * display default values - * - * @return mixed[] $real_null_value, $data, $special_chars - * @psalm-return array{bool, string, string} */ - private function getSpecialCharsAndBackupFieldForInsertingMode( + private function getSpecialCharsForInsertingMode( string|null $defaultValue, string $trueType, - ): array { - $realNullValue = false; + ): string { if ($defaultValue === null) { - $realNullValue = true; $defaultValue = ''; } @@ -921,7 +916,7 @@ class InsertEdit $specialChars = htmlspecialchars($defaultValue); } - return [$realNullValue, $defaultValue, $specialChars]; + return $specialChars; } /** @@ -1844,19 +1839,16 @@ class InsertEdit } else { // (we are inserting) // display default values - $tmp = $column; + $defaultValue = $column['Default'] ?? null; if (isset($repopulate[$fieldHashMd5])) { - $tmp['Default'] = $repopulate[$fieldHashMd5]; + $defaultValue = $repopulate[$fieldHashMd5]; } - [ - $realNullValue, - $data, - $specialChars, - ] = $this->getSpecialCharsAndBackupFieldForInsertingMode($tmp['Default'] ?? null, $tmp['True_Type']); + $realNullValue = $defaultValue === null; + $data = (string) $defaultValue; + $specialChars = $this->getSpecialCharsForInsertingMode($defaultValue, $column['True_Type']); $specialCharsEncoded = Util::duplicateFirstNewline($specialChars); $backupField = ''; - unset($tmp); } $idindex = ($oRows * $columnsCnt) + $columnNumber + 1; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 69e6931fde..472abfb93e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7927,6 +7927,7 @@ + @@ -7948,6 +7949,7 @@ + $defaultValue @@ -7962,8 +7964,6 @@ $rows[$keyId] $singleQuery $singleQuery - - getScripts()]]> $whereClause @@ -8026,6 +8026,8 @@ $currentValue $data + $defaultValue + $defaultValue $enumSelectedValue $enumValue $fieldsize @@ -8036,7 +8038,6 @@ $setSelectSize $singleQuery $specialChars - $transformedHtml $whereClause $whereClause diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index e8ecfb7f2a..4575b3b783 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -1162,26 +1162,26 @@ class InsertEditTest extends AbstractTestCase } /** - * Test for getSpecialCharsAndBackupFieldForInsertingMode + * Test for getSpecialCharsForInsertingMode * - * @param array $column Column parameters - * @param array $expected Expected result + * @param array $column Column parameters + * @param string $expected Expected result * @psalm-param array $column - * @psalm-param array $expected * - * @dataProvider providerForTestGetSpecialCharsAndBackupFieldForInsertingMode + * @dataProvider providerForTestGetSpecialCharsForInsertingMode */ - public function testGetSpecialCharsAndBackupFieldForInsertingMode( + public function testGetSpecialCharsForInsertingMode( array $column, - array $expected, + string $expected, ): void { $GLOBALS['cfg']['ProtectBinary'] = false; $GLOBALS['cfg']['ShowFunctionFields'] = true; - $result = (array) $this->callFunction( + /** @var string $result */ + $result = $this->callFunction( $this->insertEdit, InsertEdit::class, - 'getSpecialCharsAndBackupFieldForInsertingMode', + 'getSpecialCharsForInsertingMode', [$column['Default'] ?? null, $column['True_Type']], ); @@ -1189,46 +1189,41 @@ class InsertEditTest extends AbstractTestCase } /** - * Data provider for test getSpecialCharsAndBackupFieldForInsertingMode() + * Data provider for test getSpecialCharsForInsertingMode() * - * @return array, array}> + * @return array, string}> */ - public static function providerForTestGetSpecialCharsAndBackupFieldForInsertingMode(): array + public static function providerForTestGetSpecialCharsForInsertingMode(): array { return [ 'bit' => [ ['True_Type' => 'bit', 'Default' => 'b\'101\'', 'is_binary' => true], - [false, 'b\'101\'', '101', '101'], + '101', ], - 'char' => [['True_Type' => 'char', 'is_binary' => true], [true, '', '', '']], + 'char' => [['True_Type' => 'char', 'is_binary' => true], ''], 'time with CURRENT_TIMESTAMP value' => [ ['True_Type' => 'time', 'Default' => 'CURRENT_TIMESTAMP'], - [false, 'CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP'], + 'CURRENT_TIMESTAMP', ], 'time with current_timestamp() value' => [ ['True_Type' => 'time', 'Default' => 'current_timestamp()'], - [false, 'current_timestamp()', 'current_timestamp()', 'current_timestamp()'], + 'current_timestamp()', ], 'time with no dot value' => [ ['True_Type' => 'time', 'Default' => '10'], - [false, '10', '10.000000', '10.000000'], + '10.000000', ], 'time with dot value' => [ ['True_Type' => 'time', 'Default' => '10.08'], - [false, '10.08', '10.080000', '10.080000'], + '10.080000', ], 'any text with escape text default' => [ ['True_Type' => 'text', 'Default' => '"lorem\"ipsem"'], - [false, '"lorem\"ipsem"', 'lorem"ipsem', 'lorem"ipsem'], + 'lorem"ipsem', ], 'varchar with html special chars' => [ ['True_Type' => 'varchar', 'Default' => 'hello world
lorem ipsem'], - [ - false, - 'hello world
lorem ipsem', - 'hello world<br><b>lorem</b> ipsem', - 'hello world<br><b>lorem</b> ipsem', - ], + 'hello world<br><b>lorem</b> ipsem', ], ]; }