Improve readability of AbstractPlatform#getDefaultValueDeclarationSQL()

parent 54a83488
......@@ -2274,28 +2274,39 @@ abstract class AbstractPlatform
*/
public function getDefaultValueDeclarationSQL($field)
{
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
if ( ! isset($field['default'])) {
return empty($field['notnull']) ? ' DEFAULT NULL' : '';
}
$default = $field['default'];
if ( ! isset($field['type'])) {
return " DEFAULT '" . $default . "'";
}
if (isset($field['default'])) {
$default = " DEFAULT '" . $field['default'] . "'";
if (isset($field['type'])) {
$type = (string) $field['type'];
if (in_array($type, ["Integer", "BigInt", "SmallInt"], true)) {
$default = " DEFAULT " . $field['default'];
} elseif (in_array($type, ['DateTime', 'DateTimeTz', 'DateTimeImmutable', 'DateTimeTzImmutable'], true) && $field['default'] === $this->getCurrentTimestampSQL()) {
$default = " DEFAULT " . $this->getCurrentTimestampSQL();
} elseif (in_array($type, ['Time', 'TimeImmutable'], true) && $field['default'] === $this->getCurrentTimeSQL()) {
$default = " DEFAULT " . $this->getCurrentTimeSQL();
} elseif (in_array($type, ['Date', 'DateImmutable'], true) && $field['default'] === $this->getCurrentDateSQL()) {
$default = " DEFAULT " . $this->getCurrentDateSQL();
} elseif ($type === 'Boolean') {
$default = " DEFAULT '" . $this->convertBooleans($field['default']) . "'";
return " DEFAULT " . $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