From aa689f04f33d3549f3087e84ce74a47247ad62e9 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 20 Apr 2023 00:12:20 +0100 Subject: [PATCH] Drop getEnumSetAndTimestampColumns() Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 40 +++++------------ test/classes/InsertEditTest.php | 77 -------------------------------- 2 files changed, 12 insertions(+), 105 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index c1af786bb0..78aeb8145c 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -329,11 +329,18 @@ class InsertEdit ['char', 'varchar'], ); - [ - $column['pma_type'], - $column['wrap'], - $column['first_timestamp'], - ] = $this->getEnumSetAndTimestampColumns($column, $timestampSeen); + $column['pma_type'] = match ($column['True_Type']) { + 'set', 'enum' => $column['True_Type'], + default => $column['Type'] + }; + + $column['wrap'] = match ($column['True_Type']) { + 'set', 'enum' => '', + default => ' text-nowrap' + }; + + // can only occur once per table + $column['first_timestamp'] = $column['True_Type'] === 'timestamp' ? ! $timestampSeen : false; return $column; } @@ -376,29 +383,6 @@ class InsertEdit return false; } - /** - * Retrieve set, enum, timestamp table columns - * - * @param mixed[] $column description of column in given table - * @param bool $timestampSeen whether a timestamp has been seen - * - * @return mixed[] $column['pma_type'], $column['wrap'], $column['first_timestamp'] - * @psalm-return array{0: mixed, 1: string, 2: bool} - */ - private function getEnumSetAndTimestampColumns(array $column, bool $timestampSeen): array - { - return match ($column['True_Type']) { - 'set' => ['set', '', false], - 'enum' => ['enum', '', false], - 'timestamp' => [ - $column['Type'], - ' text-nowrap', - ! $timestampSeen, // can only occur once per table - ], - default => [$column['Type'], ' text-nowrap', false], - }; - } - /** * Retrieve the nullify code for the null column * diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 166cf2069e..66bf95c010 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -530,83 +530,6 @@ class InsertEditTest extends AbstractTestCase $this->assertFalse($this->insertEdit->isColumn($column, $types)); } - /** - * Test for getEnumSetAndTimestampColumns - */ - public function testGetEnumAndTimestampColumns(): void - { - $column = []; - $column['True_Type'] = 'set'; - $this->assertEquals( - ['set', '', false], - $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getEnumSetAndTimestampColumns', - [$column, false], - ), - ); - - $column['True_Type'] = 'enum'; - $this->assertEquals( - ['enum', '', false], - $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getEnumSetAndTimestampColumns', - [$column, false], - ), - ); - - $column['True_Type'] = 'timestamp'; - $column['Type'] = 'date'; - $this->assertEquals( - ['date', ' text-nowrap', true], - $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getEnumSetAndTimestampColumns', - [$column, false], - ), - ); - - $column['True_Type'] = 'timestamp'; - $column['Type'] = 'date'; - $this->assertEquals( - ['date', ' text-nowrap', false], - $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getEnumSetAndTimestampColumns', - [$column, true], - ), - ); - - $column['True_Type'] = 'SET'; - $column['Type'] = 'num'; - $this->assertEquals( - ['num', ' text-nowrap', false], - $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getEnumSetAndTimestampColumns', - [$column, false], - ), - ); - - $column['True_Type'] = ''; - $column['Type'] = 'num'; - $this->assertEquals( - ['num', ' text-nowrap', false], - $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getEnumSetAndTimestampColumns', - [$column, false], - ), - ); - } - /** * Test for getNullifyCodeForNullColumn */