staabm / phpstan-dba

PHPStan based SQL static analysis and type inference for the database access layer
https://staabm.github.io/archive.html#phpstan-dba
MIT License
255 stars 17 forks source link

DoctrineKeyValueStyeRule: allow int values in float columns #581

Closed hemberger closed 1 year ago

hemberger commented 1 year ago

Using $databaseType->isSuperTypeOf($valueType) to check if the input value type matches the database column type was too strict. It was incorrectly raising errors for various legal scenarios, e.g.:

The accepts method correctly handles these cases. Add extra logic for MixedType, since mixed types are always accepted.

NOTE: The MixedType case may be demoted to a debug-mode-only error, depending on the answer to https://github.com/staabm/phpstan-dba/pull/564#discussion_r1141097432.

staabm commented 1 year ago

Passing a benevolent (float|int) to an int column.

do you say a regular float|int works but a benevolent (float|int) does not? I kind of can't believe it :)

hemberger commented 1 year ago

do you say a regular float|int works but a benevolent (float|int) does not? I kind of can't believe it :)

Given an int column, float|int is an error (as it should be), but currently (float|int) is also an error, and I was thinking that perhaps it shouldn't be given this documentation about them:

Benevolent unions aren’t checked strictly even at the highest level

But if you say otherwise, I'll take your word for it! :)

staabm commented 1 year ago

Benevolent unions aren’t checked strictly even at the highest level

i guess you took that sentence from the phpstan docs somewhere? If so: it describes how native phpstan rules behave according to analysis level.

atm the phpstan-dba rules do not at all depend on phpstan rule levels (which does not mean that our RuntimeConfig could take inspiration of the ideas behind phpstan-src rules or implement similar ideas).

i don‘t know how phpstan-dba rules work with benevolent unions atm. We would need unit tests to verify it

staabm commented 1 year ago

thank you