Skip to content

Commit b39afd7

Browse files
authored
[MySQL] Treat decimal as numeric-string (#429)
* Treat decimal as numeric-string * record? * no error here * please new version of phpstan * record with mysql 8 * Wrap accessory numeric string type in intersection type
1 parent f60f559 commit b39afd7

27 files changed

+9186
-10487
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 123 additions & 327 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpstan-dba-pdo-mysql.cache

Lines changed: 58 additions & 556 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QueryReflection/PdoMysqlQueryReflector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected function simulateQuery(string $queryString)
8383
$columnMeta['flags'][] = $flag;
8484
}
8585

86-
// @phpstan-ignore-next-line
8786
$this->cache[$queryString][$columnIndex] = $columnMeta;
8887
++$columnIndex;
8988
}

src/TypeMapping/MysqlTypeMapper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,20 @@ public function mapToPHPStanType(string $mysqlType, array $mysqlFlags, int $leng
117117
$phpstanType = IntegerRangeType::fromInterval(0, 2155);
118118
}
119119
// floats are detected as numerics in mysqli
120-
if (\in_array(strtoupper($mysqlType), ['DOUBLE', 'NEWDECIMAL', 'REAL'], true)) {
120+
if (\in_array(strtoupper($mysqlType), ['DOUBLE', 'REAL'], true)) {
121121
$phpstanType = new FloatType();
122122
}
123123

124124
// fallbacks
125125
if (null === $phpstanType) {
126126
switch (strtoupper($mysqlType)) {
127+
case 'DECIMAL':
128+
case 'NEWDECIMAL':
129+
$phpstanType = new IntersectionType([
130+
new StringType(),
131+
new AccessoryNumericStringType(),
132+
]);
133+
break;
127134
case 'LONGLONG':
128135
case 'LONG':
129136
case 'SHORT':

0 commit comments

Comments
 (0)