From 708f6a2334f2dc3984841123bcfe6f8a8cf9cd5c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 26 Nov 2023 16:12:39 +0700 Subject: [PATCH 1/2] Refactor `AbstractSchema::getDataType()` --- src/Schema/AbstractSchema.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index cd1c89cb0..67b0a4c27 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -133,19 +133,14 @@ public function getDefaultSchema(): string|null public function getDataType(mixed $data): int { - /** @psalm-var array $typeMap */ - $typeMap = [ + return match (gettype($data)) { // php type => SQL data type SchemaInterface::PHP_TYPE_BOOLEAN => DataType::BOOLEAN, SchemaInterface::PHP_TYPE_INTEGER => DataType::INTEGER, - SchemaInterface::PHP_TYPE_STRING => DataType::STRING, SchemaInterface::PHP_TYPE_RESOURCE => DataType::LOB, SchemaInterface::PHP_TYPE_NULL => DataType::NULL, - ]; - - $type = gettype($data); - - return $typeMap[$type] ?? DataType::STRING; + default => DataType::STRING, + }; } public function getRawTableName(string $name): string From dbb35eccb87260570f26739e2576ec5d12bc8dcd Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 26 Nov 2023 16:17:47 +0700 Subject: [PATCH 2/2] Add line to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af82ceefc..9fb988a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ `DbArrayHelper::populate()` methods to `array[]` (@vjik) - Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik) - Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov) +- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov) ## 1.2.0 November 12, 2023