Skip to content

Commit

Permalink
Update Schema::normalizeDefaultValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jul 20, 2023
1 parent 032e1b3 commit b380551
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,20 +505,20 @@ protected function loadColumnSchema(array $info): ColumnSchemaInterface
* @param ColumnSchemaInterface $column The column schema object.
*
* @return mixed The normalized default value.
*
* @psalm-suppress PossiblyNullArgument
*/
private function normalizeDefaultValue(?string $defaultValue, ColumnSchemaInterface $column): mixed
private function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaInterface $column): mixed
{
if ($column->isPrimaryKey()) {
if ($column->isPrimaryKey() || in_array($defaultValue, [null, '', 'null', 'NULL'], true)) {
return null;
}

return match ($defaultValue) {
null, 'null', '' => null,
'CURRENT_TIMESTAMP', 'CURRENT_DATE', 'CURRENT_TIME' => new Expression($defaultValue),
default => $column->phpTypecast(trim($defaultValue, "'\"")),
};
if (in_array($defaultValue, ['CURRENT_TIMESTAMP', 'CURRENT_DATE', 'CURRENT_TIME'], true)) {
return new Expression($defaultValue);
}

$value = preg_replace('/^([\'"])(.*)\1$/s', '$2', $defaultValue);

return $column->phpTypecast($value);
}

/**
Expand Down

0 comments on commit b380551

Please sign in to comment.