Skip to content

Commit

Permalink
Use match()
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-boudry committed Oct 9, 2023
1 parent 0df5e85 commit fae9f5b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/DataFrameCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,13 @@ public function convertTypes(array $typeMap, array|string|null $fromDateFormat =
{
foreach ($this as $i => $row) {
foreach ($typeMap as $column => $type) {
if ($type === DataType::NUMERIC) {
$this->data[$i][$column] = $this->convertNumeric($row[$column]);
} elseif ($type === DataType::INTEGER) {
$this->data[$i][$column] = $this->convertInt($row[$column]);
} elseif ($type === DataType::DATETIME) {
$this->data[$i][$column] = $this->convertDatetime($row[$column], $fromDateFormat, $toDateFormat);
} elseif ($type == DataType::CURRENCY) {
$this->data[$i][$column] = $this->convertCurrency($row[$column]);
} elseif ($type == DataType::ACCOUNTING) {
$this->data[$i][$column] = $this->convertAccounting($row[$column]);
}
$this->data[$i][$column] = match($type) {
DataType::NUMERIC => $this->convertNumeric($row[$column]),
DataType::INTEGER => $this->convertInt($row[$column]),
DataType::DATETIME => $this->convertDatetime($row[$column], $fromDateFormat, $toDateFormat),
DataType::CURRENCY => $this->convertCurrency($row[$column]),
DataType::ACCOUNTING => $this->convertAccounting($row[$column]),
};
}
}
}
Expand Down

0 comments on commit fae9f5b

Please sign in to comment.