Skip to content

Commit

Permalink
Refactor AbstractSchema::getDataType() (#786)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
Tigrov and vjik committed Nov 26, 2023
1 parent f655cb7 commit f06cf26
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
11 changes: 3 additions & 8 deletions src/Schema/AbstractSchema.php
Expand Up @@ -134,19 +134,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 f06cf26

Please sign in to comment.