Extra: Replace Squiz.Scope.MemberVarScope
with PSR2.Classes.PropertyDeclaration
#1592
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #1103 added the
Squiz.Scope.MemberVarScope
sniff to theWordPress-Extra
ruleset which checks that all class properties have their visibility declared.The upstream
PSR2.Classes.PropertyDeclaration
sniff also does this, however it contains more extensive checks.In addition to checking for the visibility of properties being declared, this sniff also checks:
_
to indicate visibility.For methods, we already check this in the
Extra
ruleset via thePSR2.Methods.MethodDeclaration
sniff.var
keyword is not used for property declarations.This could be considered a duplicate check with the "use visibility" check.
As there is no precedent or reference to this type of property declarations in the handbook or elsewhere in the various rulesets, I'm not sure that we're ready to take a stand on this type of coding, so I've excluded this particular error code for now.Even though there is no precedent or reference to this type of property declarations in the handbook or elsewhere in the various rulesets, WP Core itself does not appear to use multi-property assignments, so we may as well check leave the check in for now.
People can always still exclude it in their own custom rulesets and if we'd get a lot of push-back, we can reconsider.
visibility static
, notstatic visibility
(includes fixer).For methods, we already check this in the
Extra
ruleset via thePSR2.Methods.MethodDeclaration
sniff.All in all, using the
PSR2
sniff is more in line with the checks we already have in place for methods, so IMO, this seemed like a good change to make.