Skip to content

Commit 0f7dd29

Browse files
committed
fix(entity): default int value
1 parent 3a31be0 commit 0f7dd29

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/Creators/CreatorEntity.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,38 @@ public function createAttributes(): array
3838
$attributes = [];
3939

4040
foreach ($columns as $_column) {
41+
4142
$dataType = $this->getDataType($_column->COLUMN_TYPE, $_column->DATA_TYPE);
42-
$defaultValue = ($_column->COLUMN_DEFAULT ?? 'null') ? ($_column->COLUMN_DEFAULT ?? 'null') : "''";
4343

44-
$defaultValue = ($dataType == self::BOOL_TYPE) ? ((in_array($defaultValue, [0, '', "''"])) ? 'false' :
45-
((in_array($defaultValue, [1, '1'])) ? 'true' : $defaultValue)) : $defaultValue;
44+
$defaultValue = null;
45+
if ($_column->COLUMN_DEFAULT !== null) {
46+
$defaultValue = $_column->COLUMN_DEFAULT;
47+
48+
if ($dataType == 'int') {
49+
$defaultValue = intval($defaultValue);
50+
}
51+
52+
if ($dataType == self::BOOL_TYPE) {
53+
if (in_array($defaultValue, [0, '', "''"])) {
54+
$defaultValue = 'false';
55+
} elseif (in_array($defaultValue, [1, '1'])) {
56+
$defaultValue = 'true';
57+
}
58+
}
59+
}
60+
61+
$columnString = $_column->COLUMN_NAME;
62+
if (!in_array($_column->COLUMN_DEFAULT, [null, 'NULL'])) {
63+
$columnString .= ' = ' . $defaultValue;
64+
}
65+
if ($_column->IS_NULLABLE === 'YES') {
66+
$columnString .= ' = null';
67+
}
4668

4769
$attributes[$_column->COLUMN_NAME] =
4870
$this->writeAttribute(
4971
$entityStubsPath,
50-
$_column->COLUMN_NAME . (!in_array($_column->COLUMN_DEFAULT, [null, 'NULL']) ? ' = ' . $defaultValue : ''),
72+
$columnString,
5173
($_column->IS_NULLABLE === 'YES' ? 'null|' : '') . $dataType
5274
);
5375
}

0 commit comments

Comments
 (0)