Improve readability of AbstractPlatform#getDefaultValueDeclarationSQL()

parent 54a83488
...@@ -2274,28 +2274,39 @@ abstract class AbstractPlatform ...@@ -2274,28 +2274,39 @@ abstract class AbstractPlatform
*/ */
public function getDefaultValueDeclarationSQL($field) public function getDefaultValueDeclarationSQL($field)
{ {
$default = empty($field['notnull']) ? ' DEFAULT NULL' : ''; if ( ! isset($field['default'])) {
return empty($field['notnull']) ? ' DEFAULT NULL' : '';
if (isset($field['default'])) { }
$default = " DEFAULT '" . $field['default'] . "'";
if (isset($field['type'])) { $default = $field['default'];
$type = (string) $field['type'];
if ( ! isset($field['type'])) {
if (in_array($type, ["Integer", "BigInt", "SmallInt"], true)) { return " DEFAULT '" . $default . "'";
$default = " DEFAULT " . $field['default']; }
} elseif (in_array($type, ['DateTime', 'DateTimeTz', 'DateTimeImmutable', 'DateTimeTzImmutable'], true) && $field['default'] === $this->getCurrentTimestampSQL()) {
$default = " DEFAULT " . $this->getCurrentTimestampSQL(); $type = (string) $field['type'];
} elseif (in_array($type, ['Time', 'TimeImmutable'], true) && $field['default'] === $this->getCurrentTimeSQL()) {
$default = " DEFAULT " . $this->getCurrentTimeSQL(); if (in_array($type, ["Integer", "BigInt", "SmallInt"], true)) {
} elseif (in_array($type, ['Date', 'DateImmutable'], true) && $field['default'] === $this->getCurrentDateSQL()) { return " DEFAULT " . $default;
$default = " DEFAULT " . $this->getCurrentDateSQL(); }
} elseif ($type === 'Boolean') {
$default = " DEFAULT '" . $this->convertBooleans($field['default']) . "'"; if (in_array($type, ['DateTime', 'DateTimeTz', 'DateTimeImmutable', 'DateTimeTzImmutable'], true) && $default === $this->getCurrentTimestampSQL()) {
} return " DEFAULT " . $this->getCurrentTimestampSQL();
} }
if (in_array($type, ['Time', 'TimeImmutable'], true) && $default === $this->getCurrentTimeSQL()) {
return " DEFAULT " . $this->getCurrentTimeSQL();
}
if (in_array($type, ['Date', 'DateImmutable'], true) && $default === $this->getCurrentDateSQL()) {
return " DEFAULT " . $this->getCurrentDateSQL();
}
if ($type === 'Boolean') {
return " DEFAULT '" . $this->convertBooleans($default) . "'";
} }
return $default; return " DEFAULT '" . $default . "'";
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment