-
-
Notifications
You must be signed in to change notification settings - Fork 23
[MySQL] Treat decimal as numeric-string #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| // fallbacks | ||
| if (null === $phpstanType) { | ||
| switch (strtoupper($mysqlType)) { | ||
| case 'DECIMAL': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this is probably redundant)
| $query = 'SELECT MAX(adaid), MIN(adaid), COUNT(adaid), AVG(adaid) FROM ada WHERE adaid = 1'; | ||
| $stmt = $pdo->query($query, PDO::FETCH_ASSOC); | ||
| assertType('PDOStatement<array{MAX(adaid): int<-32768, 32767>|null, MIN(adaid): int<-32768, 32767>|null, COUNT(adaid): int, AVG(adaid): float|null}>', $stmt); | ||
| assertType('PDOStatement<array{MAX(adaid): int<-32768, 32767>|null, MIN(adaid): int<-32768, 32767>|null, COUNT(adaid): int, AVG(adaid): numeric-string|null}>', $stmt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and result of AVG is also a string.
staabm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great thx. Did you verify the results on mysqli and pdo+mysql?
src/TypeMapping/MysqlTypeMapper.php
Outdated
| switch (strtoupper($mysqlType)) { | ||
| case 'DECIMAL': | ||
| case 'NEWDECIMAL': | ||
| $phpstanType = new AccessoryNumericStringType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See line 161 how a numeric string is built. An accessory type cannot stand on its own in the phpstan type system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I've seen it, but instantiated it just like this and it seems to work ? 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for the tests but will not work in the bigger picture when the type needs to be combined with other logic within phpstan
I have tested only with pdo. I can do some more testing before we merge this |
best code |
|
Awesome thx, just pushed a new bugfix release |
Closes #428.