Skip to content

Commit f06cf26

Browse files
Tigrovvjik
andauthored
Refactor AbstractSchema::getDataType() (#786)
Co-authored-by: Sergei Predvoditelev <[email protected]>
1 parent f655cb7 commit f06cf26

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
`DbArrayHelper::populate()` methods to `array[]` (@vjik)
99
- Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik)
1010
- Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov)
11+
- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov)
1112
- Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik)
1213
- Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik)
1314

src/Schema/AbstractSchema.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,14 @@ public function getDefaultSchema(): string|null
134134

135135
public function getDataType(mixed $data): int
136136
{
137-
/** @psalm-var array<string, int> $typeMap */
138-
$typeMap = [
137+
return match (gettype($data)) {
139138
// php type => SQL data type
140139
SchemaInterface::PHP_TYPE_BOOLEAN => DataType::BOOLEAN,
141140
SchemaInterface::PHP_TYPE_INTEGER => DataType::INTEGER,
142-
SchemaInterface::PHP_TYPE_STRING => DataType::STRING,
143141
SchemaInterface::PHP_TYPE_RESOURCE => DataType::LOB,
144142
SchemaInterface::PHP_TYPE_NULL => DataType::NULL,
145-
];
146-
147-
$type = gettype($data);
148-
149-
return $typeMap[$type] ?? DataType::STRING;
143+
default => DataType::STRING,
144+
};
150145
}
151146

152147
public function getRawTableName(string $name): string

0 commit comments

Comments
 (0)