The PSR12 ruleset includes a severity override that promotes PSR2.Methods.MethodDeclaration.Underscore from warning to error and customises the message text from "should not" to "must not", matching the MUST NOT wording in PSR-12 section 4.4.
The equivalent rule for properties in PSR-12 section 4.3 uses identical MUST NOT wording, but no matching override exists for PSR2.Classes.PropertyDeclaration.Underscore. As a result, a property with a leading underscore is reported as a warning, while a method with a leading underscore is reported as an error.
Both were introduced in b7fed6b, but only the method override was applied.
Given the following code sample:
<?php
namespace MyNamespace;
class MyClass
{
public $_foo;
protected function _bar()
{
}
}
Running phpcs --standard=PSR12 against this file produces:
7 | WARNING | Property name "$_foo" should not be prefixed with an underscore to indicate visibility
8 | ERROR | Method name "_bar" must not be prefixed with an underscore to indicate visibility
I wonder if there's a reason I'm missing to treat the property rule as a warning or if the PSR12 ruleset should be updated? If the latter, I can open a PR suggesting this change.
The PSR12 ruleset includes a severity override that promotes
PSR2.Methods.MethodDeclaration.Underscorefrom warning to error and customises the message text from "should not" to "must not", matching theMUST NOTwording in PSR-12 section 4.4.The equivalent rule for properties in PSR-12 section 4.3 uses identical
MUST NOTwording, but no matching override exists forPSR2.Classes.PropertyDeclaration.Underscore. As a result, a property with a leading underscore is reported as a warning, while a method with a leading underscore is reported as an error.Both were introduced in b7fed6b, but only the method override was applied.
Given the following code sample:
Running
phpcs --standard=PSR12against this file produces:I wonder if there's a reason I'm missing to treat the property rule as a warning or if the PSR12 ruleset should be updated? If the latter, I can open a PR suggesting this change.