-
-
Notifications
You must be signed in to change notification settings - Fork 205
Add new sniff for PHP 8.4 deprecation - implicit nullable parameter types #1689
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
Add new sniff for PHP 8.4 deprecation - implicit nullable parameter types #1689
Conversation
|
Shoot. I actually already wrote a sniff for this two days ago, but hadn't pulled it yet as I'm waiting for 3v4l to update their PHP Okay, guess we'll have to see about merging the two sniffs. Will have to have a look at this next week. As a side-note, I will most definitely not accept an auto-fixer for this issue as there are multiple fixes possible and the sniff can not decide which is the most appropriate fix. |
1279ae7 to
66e6ce4
Compare
Are you referring to
I win. 😄
It's probably worth at least comparing the two sets of tests. Is your version publicly available, or only accessible to you? |
No, I'm not. While, in the fast majority of cases, adding the nullability operator will be the "simple" fix, there are other options and only someone who is familiar with how the project under scan is used (open/closed source, code is being extended/methods overloaded or not) can take the decision what the correct fix is and what fix is chosen may also depend on whether the next version of the project is a major or not, as some of the fixes constitute breaking changes to one degree or another. Aside from adding the nullability operator, these are various other possible choices to bypass/fix the deprecation:
Also keep in mind the nullability operator can only be used when the minimum supported PHP version is PHP 7.1 or higher. The fixer you wrote does not take the minimum PHP version of the code under scan into account, which means the fixer will introduce parse errors into projects (which have a minimum < 7.1).
Eh... you know that's not how this works ?
It's not public yet (as I wanted to validate against 3v4l first). I'll have a look see if they have updated the PHP version in the mean time, but I can push the branch for you to see anyway. |
I just compared the tests. My sniff correctly handles your test file. I win 😝 (that is, presuming of course, that our tests actually match the reality of PHP, which I still haven't been able to validate) You can find my branch here: https://github.com/PHPCompatibility/PHPCompatibility/tree/php-8.4/new-removedimplicitlynullableparam-sniff |
|
Based on the feedback in PHPCSStandards/PHPCSUtils#566 and PHPCSStandards/PHPCSUtils#567, it seems that we can't trust Also, as @jrfnl has already done the work in duplicate of writing a sniff for this PHP deprecation, it seems that /that/ sniff is more likely to be accepted in this project than /this/ sniff. With all this in mind, I think we should close this pull request in favour of the will-be-created pull request from @jrfnl for the same. |
We can trust There will be other helpers available in Utils in the future for analyzing types and I'd be happy to ping you for feedback on the ones I have in mind, either before they are public, or once I've pulled the PR (but definitely before they are released).
Sorry, that's not how it works either. I recognize the work you put into this and (aside from a fixer not being acceptable) there are small other differences between our sniffs. In my mind, the next step is resolving those differences and updating one or the other of the sniffs to be the best of both worlds and making sure we are both recognized as I have had a (private) response from 3v4l by now, so I expect that the tooling will be updated soonish to validate the tests. Let's discuss merging the other differences once the tests are validated. Is that okay with you ? As a side-note and to (hopefully) avoid more duplicate work: the The lesson for me from this ticket is that, if there are going to be more people actively contributing code to this project, we need to find a way to communicate work started/in progress better. For RFC based sniffs, I normally open an "account for PHP x.x changes" ticket around the time the RFC window closes and annotate in that ticket what is being worked on/claimed by someone to prevent duplicate work. That time is still a few months away though and as this is such a high impact RFC, this one just felt like something to address earlier. Maybe either of us should have opened an issue before starting work on the sniff ? (to prevent the duplication) What are your thoughts on this ? |
I expected the Let's pick this up on our call next week and we can write an update here following that with any noteworthy discussion points and decisions/actions. |
|
@fredden The fact that PHPCS (and by extension PHPCSUtils) doesn't support DNF yet is a known fact and IMO irrelevant for this sniff. This is being discussed in PHPCSStandards/PHP_CodeSniffer#387, which is where that discussion belongs. |
|
FYI: 3v4l has been updated, so I'll be verifying the tests later today. |
|
Based on the tests I've been running so far:
@fredden 👆🏻 This is exactly the kind of thing why I waited to pull my version of the sniff and wanted to validate the test cases first. |
|
@fredden I've updated my version of the sniff based on the above findings and have added a few extra test cases based on the tests in your sniff. I've made the changes largely in new commits for the time being, so you can see what I've changed. Please let me know if you see anything else which should be included from your sniff. If not, I'll squash the commits (and keep the joined credits) and I propose I pull that branch to replace this PR. |
https://wiki.php.net/rfc/deprecate-implicitly-nullable-types
Implicit nullable parameter types are now deprecated as of PHP 8.4 and will stop working as of PHP 9.0. This pull request adds a warning when the deprecation applies and an error when the feature will stop working. I have included a fixer for this change.
There is currently only one other ".fixed" file in this repository, but it does not appear to be used by anything. I have added a method to the base test class to allow testing the fixer against ".fixed" files. I have opened #1690 to ensure that file gets suitable test coverage. That pull request contains the same method to the base test class.
The test-suite here will not work yet, as there is at least one bug in
\PHPCSUtils\Utils\FunctionDeclarations::getParameters(). I intend to investigate that next. It's likely that we will need to bump the minimum version of that package as part of this pull request after that's fixed.