Skip to content

Commit ed7aeae

Browse files
Seldaekstaabm
andauthored
Add support for JSON columns and nullability for string column types (#110)
Co-authored-by: Markus Staab <[email protected]>
1 parent 6e926b2 commit ed7aeae

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/QueryReflection/MysqliQueryReflector.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,31 @@ private function mapMysqlToPHPStanType(int $mysqlType, int $mysqlFlags, int $len
216216
$phpstanType = $mysqlIntegerRanges->unsignedInt();
217217
}
218218

219-
if ($phpstanType) {
220-
if (false === $notNull) {
221-
$phpstanType = TypeCombinator::addNull($phpstanType);
219+
if (null === $phpstanType) {
220+
switch ($this->type2txt($mysqlType)) {
221+
case 'LONGLONG':
222+
case 'LONG':
223+
case 'SHORT':
224+
$phpstanType = new IntegerType();
225+
break;
226+
case 'CHAR':
227+
case 'STRING':
228+
case 'VAR_STRING':
229+
case 'JSON':
230+
$phpstanType = new StringType();
231+
break;
232+
case 'DATE': // ???
233+
case 'DATETIME': // ???
234+
default:
235+
$phpstanType = new MixedType();
222236
}
223-
224-
return $phpstanType;
225237
}
226238

227-
switch ($this->type2txt($mysqlType)) {
228-
case 'LONGLONG':
229-
case 'LONG':
230-
case 'SHORT':
231-
return new IntegerType();
232-
case 'CHAR':
233-
case 'STRING':
234-
case 'VAR_STRING':
235-
return new StringType();
236-
case 'DATE': // ???
237-
case 'DATETIME': // ???
239+
if (false === $notNull) {
240+
$phpstanType = TypeCombinator::addNull($phpstanType);
238241
}
239242

240-
return new MixedType();
243+
return $phpstanType;
241244
}
242245

243246
private function type2txt(int $typeId): ?string

0 commit comments

Comments
 (0)