There must be a sniff to detect `final private` methods as they throw warnings on PHP >= 8.0
anton-vlasenko opened this issue · 4 comments
Is your feature request related to a problem?
Defining a final private method generates warnings on PHP >= 8.0:
Private methods cannot be final as they are never overridden by other classes in ...
Describe the solution you'd like
Linters should detect such methods and warn developers about them.
Code example: https://3v4l.org/uGDbO
Hi @anton-vlasenko Such a sniff exists in the PHPCompatibility[WP] standard: PHPCompatibility.FunctionDeclarations.ForbiddenFinalPrivateMethods
. The sniff is currently in the develop
branch, but will be included in PHPCompatibility 10.0.0 (PHPCompatibilityWP 3.0.0).
As per the README, we highly recommend projects in the WP sphere to also use the PHPCompatibilityWP standard, but we will not include PHPCompatibility sniffs in WordPressCS.
Is that enough for you to get unblocked ?
Thanks for the hint, @jrfnl!
I should have checked the dev branch as well.
The current stable version of PHPCompatibilityWP doesn't detect final private methods, so I thought there was no sniff for that. I'm glad that it already exists.
I think this issue can be closed now (please feel free to reopen it if needed).
Thanks!
@anton-vlasenko Glad it helped. Closing the issue is good as it doesn't really belong in this repo anyway (rather in the PHPCompatibility repo).
Closing the issue is good as it doesn't really belong in this repo anyway (rather in the PHPCompatibility repo).
Thanks. That's good to know, @jrfnl.