Skip to content

PHP 8.4 | ✨ New PHPCompatibility.FunctionDeclarations.RemovedImplicitlyNullableParam sniff (RFC)#1694

Merged
wimg merged 1 commit intodevelopfrom
php-8.4/new-removedimplicitlynullableparam-sniff
Mar 31, 2024
Merged

PHP 8.4 | ✨ New PHPCompatibility.FunctionDeclarations.RemovedImplicitlyNullableParam sniff (RFC)#1694
wimg merged 1 commit intodevelopfrom
php-8.4/new-removedimplicitlynullableparam-sniff

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 25, 2024

PHP 8.4 | ✨ New PHPCompatibility.FunctionDeclarations.RemovedImplicitlyNullableParam sniff (RFC)

As this deprecation looks to be high frequency - 880 packages out of the top 2000 Composer packages affected and that's just the tip of the iceberg -, I figured it would be good to have a sniff available early.

The fix for the issue is relatively easy and there are multiple options available, though some could result in BC-breaks for the package making the fix.

Includes tests and documentation.

Refs:

Closes #1689

…tlyNullableParam` sniff (RFC)

> - Core:
>   . Implicitly nullable parameter types are now deprecated.
>     RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types

As this deprecation looks to be high frequency - 880 packages out of the top 2000 Composer packages affected and that's just the tip of the iceberg -, I figured it would be good to have a sniff available early.

The fix for the issue is relatively easy and there are multiple options available, though some could result in BC-breaks for the package making the fix.

Includes tests and documentation.

Refs:
* https://wiki.php.net/rfc/deprecate-implicitly-nullable-types
* https://github.com/php/php-src/blob/330cc5cdb2096c5d41041eaae1f1cc0ed7e36898/UPGRADING#L271C1-L273C70
* php/php-src 12959
* php/php-src@330cc5c

Partially based on PR 1689

Co-authored-by: Dan Wallis <dan@wallis.nz>
@andrewnicols
Copy link

The fix for the issue is relatively easy and there are multiple options available, though some could result in BC-breaks for the package making the fix.

Just to clarify for anyone coming to this issue that this would only be the case for packages supporting PHP <= 7.0. This 3v4l example demonstrates the options.

Copy link

@andrewnicols andrewnicols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Snfif looks good to me. I know that PHPCompatibility rarely fixes things, but this one is going to be a pain in the back side for a whole lot of developers in a lot of places, and is really pretty easy to fix.

Obviously this one is up to you as maintainer but if you aren't going to include this, I'll be copying this sniff and adding the fix to our local ruleset anyway ;)

Copy link

@andrewnicols andrewnicols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I've just seen your response re auto-fix on #1689 so changing my response to an Approve.

I'll keep my suggestion here because, for the vast majority of projects, it will be probably be sufficient.

@jrfnl
Copy link
Member Author

jrfnl commented Mar 27, 2024

Obviously this one is up to you as maintainer but if you aren't going to include this, I'll be copying this sniff and adding the fix to our local ruleset anyway ;)

@andrewnicols I would warn you off from copying the sniff as you would be violating copyright (and offending me).

If you want the most obvious solution - making the parameter nullable - and your codebase's minimum PHP version allows for it, I would recommend you include the SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue sniff in your coding standard, which was also mentioned in the RFC at my recommendation. That sniff will auto-fix the issue as a matter of code style.

@andrewnicols
Copy link

@andrewnicols I would warn you off from copying the sniff as you would be violating copyright (and offending me).

No offense is intended. My understanding was that this sniff is licensed under the LGPL3 though, which I understood would permit copying and modifying as required. In any case, I do not intend to upset or offend.

If you want the most obvious solution - making the parameter nullable - and your codebase's minimum PHP version allows for it, I would recommend you include the SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue sniff in your coding standard, which was also mentioned in the RFC at my recommendation. That sniff will auto-fix the issue as a matter of code style.

The Slevomat sniff is absoltuely massive and has a number of bloated dependencies that we are keen to avoid. This is not a set and forget situation for us as our community has hundreds of plugins that need to be updated in the same way.

I had planned to write my own Sniff so I guess I'll go back down that road.

@jrfnl
Copy link
Member Author

jrfnl commented Mar 27, 2024

No offense is intended. My understanding was that this sniff is licensed under the LGPL3 though, which I understood would permit copying and modifying as required. In any case, I do not intend to upset or offend.

IANAL, but as far as I understand it, forking and updating (while retaining the original commits and copyright) is okay. Copying, adjusting and then passing it off as your own, is not.

The Slevomat sniff is absoltuely massive and has a number of bloated dependencies that we are keen to avoid. This is not a set and forget situation for us as our community has hundreds of plugins that need to be updated in the same way.

Could you elaborate on that ? I mean: the Slevomat sniff collection is large, true, but you would only be using one sniff of it in this case.
As for dependencies, they only have three - two of which overlap with PHPCompatibility:

	"require": {
		"php": "^7.2 || ^8.0",
		"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0",
		"phpstan/phpdoc-parser": "^1.23.1",
		"squizlabs/php_codesniffer": "^3.9.0"
	},

So, you're only really talking about the phpstan/phpdoc-parser dependency and that dependency has no underlying dependencies either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants