diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c06c3a7..549983ded 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) - Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik) - Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik) diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 7e88d45f6..f9f39e400 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -134,19 +134,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