Skip to content

Commit

Permalink
Refactor AbstractSchema::getDataType()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Nov 26, 2023
1 parent 8a3d81f commit 708f6a2
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Schema/AbstractSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,14 @@ public function getDefaultSchema(): string|null

public function getDataType(mixed $data): int
{
/** @psalm-var array<string, int> $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
Expand Down

0 comments on commit 708f6a2

Please sign in to comment.