Page MenuHomePhabricator

Question about sniff about Visibility must be declared on property
Closed, DeclinedPublic

Description

The TitleBlacklist extension contains the following code in TitleBlacklist.list.php

	private
		$mRaw,           ///< Raw line
		$mRegex,         ///< Regular expression to match
		$mParams,        ///< Parameters for this entry
		$mFormatVersion, ///< Entry format version
		$mSource;        ///< Source of this entry

which triggerd the following sniffs:

334 | ERROR   | [x] Scope keyword "private" must be followed by a single
    |         |     space
    |         |     (Squiz.WhiteSpace.ScopeKeywordSpacing.Incorrect)
335 | ERROR   | [ ] Visibility must be declared on property "$mRaw"
    |         |     (PSR2.Classes.PropertyDeclaration.ScopeMissing)

In my opinion this is valid and clean code. Should the code be changed or the sniff is wrong?
If the code should change, it would be nice to get another message, because the following code seems fine for phpcs, but is also multi statement:

	private $mBlacklist = null, $mWhitelist = null;

Event Timeline

I copied it over to https://www.mediawiki.org/wiki/Manual_talk:Coding_conventions/PHP#Declaring_multiple_properties_with_same_public.2Fprivate.2Fprotected_statement for extra visibility.

PSR2.Classes.PropertyDeclaration.ScopeMissing is definitely buggy, as visibility is set on $mRaw.

The discussion on-wiki pointed to https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#.40var:_documenting_class_members which is the accepted way to declare class member properties - as separate statements.

Marking as declined accordingly.