phpstan-doctrine
phpstan-doctrine copied to clipboard
Prevent passing null values as a request parameter
Hello,
with ORM, this code leads to invalid SQL queries when $field is null:
->andWhere('t.field = :field')
->setParameter('field', $field)
see https://github.com/doctrine/orm/issues/7289
do you think it could be nice to have a rule that checks no nullable param is passed to setParameter() / setParameters()?
I'm wondering if it would not lead to some false negatives cases where it is valid to pass null as parameter... :thinking:
This would be a nice addition 👍
If null is not supported/makes no sens to setParameter, it should be on the function signature instead https://github.com/doctrine/orm/blob/5a40b99e11a0de532eb866f062dccad20da19add/src/QueryBuilder.php#L436
Changing mixed to bool|int|float|string|array|object