-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
PSR12.Properties.ConstantVisibility should automatically detect the PHP version #393
Comments
@razvanphp Thanks for opening this issue.
PHPCS can not and should not rely on a
As spelled out in the CONTRIBUTING guide, PHPCS does not allow risky fixers for its native sniffs. The appropriate visibility is something which should be deliberately determined by a developer. This is not something a tool can do and making automated BC-compatible fixes just to fix the issues instead of making deliberate choices about the visibility is a risky fix, so any PR for this will not be accepted. I'm pretty sure there are sniffs available in external standards which can make that fix for you, but it will not be made by the PHPCS native sniffs.
The code snippet shown, works based on a configured |
ok, thanks for the detailed explanation. So no other options? I can't see a viable way to treat this case otherwise. Maybe the sniff could receive a parameter as the minimum PHP version? |
That code snippet with
A parameter would require a custom ruleset, in which case people can just as well use: <rule ref="PSR12">
<exclude name="PSR12.Properties.ConstantVisibility"/>
</rule> |
OK, for now I will just exclude it in the project |
Is your feature request related to a problem?
When running PSR12 against an (older) project, we see this warning message for projects that actually support PHP versions lower than 7.1.
In my particular case, this is defined in composer.json:
The php version running phpcs is not relevant, as it might run just in CI.
Describe the solution you'd like
It would be great to skip this check if the minimum version is below PHP 7.1, ideally checking this in composer.json. Also, I think this is an easy fix for
phpcbf
, but it's not yet implemented, it should bepublic
as this is the default visibility if it is omitted.Additional context (optional)
Can I please get some guidance of how this should be implemented? Saw in another issue this, but not sure it's reliable enough for this use-case:
PHP_CodeSniffer/src/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php
Lines 43 to 52 in 9b6260b
The text was updated successfully, but these errors were encountered: