From b3805516928bb3f1074d5c86d18095783eefa758 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 20 Jul 2023 19:42:03 +0700 Subject: [PATCH] Update `Schema::normalizeDefaultValue()` --- src/Schema.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Schema.php b/src/Schema.php index dae672a5..3012bf96 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -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); } /**