Skip to content

Commit 3626e55

Browse files
authored
Merge pull request #60 from kitloong/feature/nullcheck
Check if type information return null #58
2 parents 836f634 + f72901b commit 3626e55

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/MigrationsGenerator/Generators/Columns/DatetimeColumn.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,19 @@ private function getLength(string $table, Column $column): ?int
129129
*/
130130
private function getPgSQLLength(string $table, Column $column): ?int
131131
{
132-
$rawType = ($this->pgSQLRepository->getTypeByColumnName($table, $column->getName()));
133-
$length = $this->regex->getTextBetween($rawType);
132+
$rawType = $this->pgSQLRepository->getTypeByColumnName($table, $column->getName());
133+
if ($rawType === null) {
134+
// @codeCoverageIgnoreStart
135+
return null;
136+
// @codeCoverageIgnoreEnd
137+
}
138+
139+
$length = $this->regex->getTextBetween($rawType);
134140
if ($length !== null) {
135141
return (int) $length;
136-
} else {
137-
return null;
138142
}
143+
144+
return null;
139145
}
140146

141147
/**
@@ -158,7 +164,6 @@ private function getSQLSrvLength(string $table, Column $column): ?int
158164
} else {
159165
return $column->getScale();
160166
}
161-
// no break
162167
case DateTimeTzType::class:
163168
case DateTimeTzImmutableType::class:
164169
if ($colDef->getScale() === self::SQLSRV_DATETIME_TZ_EMPTY_SCALE &&
@@ -167,7 +172,6 @@ private function getSQLSrvLength(string $table, Column $column): ?int
167172
} else {
168173
return $column->getScale();
169174
}
170-
// no break
171175
default:
172176
return $column->getScale();
173177
}

src/MigrationsGenerator/Repositories/PgSQLRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public function getTypeByColumnName(string $table, string $column): ?string
3737
if (count($columnDetail) > 0) {
3838
return $columnDetail[0]->datatype;
3939
}
40+
41+
// @codeCoverageIgnoreStart
4042
return null;
43+
// @codeCoverageIgnoreEnd
4144
}
4245

4346
/**
@@ -71,7 +74,10 @@ public function getCheckConstraintDefinition(string $table, string $column): ?st
7174
if (count($columnDetail) > 0) {
7275
return $columnDetail[0]->definition;
7376
}
77+
78+
// @codeCoverageIgnoreStart
7479
return null;
80+
// @codeCoverageIgnoreEnd
7581
}
7682

7783
/**

0 commit comments

Comments
 (0)