PHPCSStandards / PHPCSUtils

A suite of utility functions for use with PHP_CodeSniffer
https://phpcsutils.com/
GNU Lesser General Public License v3.0
54 stars 7 forks source link

Set `nullable_type` = `true` when type is nullable #566

Closed fredden closed 7 months ago

fredden commented 7 months ago

I've been down a rabbit hole today. I started with https://github.com/PHPCompatibility/PHPCompatibility/pull/1689 and ended up here setting nullable_type to true when a type is allowed to be null.

jrfnl commented 7 months ago

@fredden Sorry you went through such a rabbit hole, but this is by design.

When union types were introduced and I added support for them to the PHPCS native getMethodParameters() method, it was decided that nullable_type is only for the nullability operator. See: https://github.com/squizlabs/PHP_CodeSniffer/issues/2968#issuecomment-653831324 and the replies to that.

The PHPCSUtils getParameters() method closely mirrors the getMethodParameters() method and should stay compatible with it, so it can be used as a one-on-one replacement.

This PR breaks that premise.

It would also be a breaking change, which can only be made in a major release.

For those reasons, I will not accept this PR.