Skip to content

Commit 051ef9f

Browse files
committed
PSR2/PropertyDeclaration: update for properties with asymmetric visibility [1]
Per the FIG PSR-PER updates (next version), the "properties must have visibility declared" rule is also satisfied if only write visibility is declared. > The `public` keyword MAY be omitted when using a set-visibility on a public-read property. Includes updated test expectations (on the tests previously added in 871). Refs: * php-fig/per-coding-style 99 * php-fig/per-coding-style 114
1 parent 2e9da03 commit 051ef9f

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
114114
}//end if
115115
}//end if
116116

117-
if ($propertyInfo['scope_specified'] === false) {
117+
if ($propertyInfo['scope_specified'] === false && $propertyInfo['set_scope'] === false) {
118118
$error = 'Visibility must be declared on property "%s"';
119119
$data = [$tokens[$stackPtr]['content']];
120120
$phpcsFile->addError($error, $stackPtr, 'ScopeMissing', $data);

src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ public function getErrorList()
6161
95 => 1,
6262
96 => 1,
6363
97 => 2,
64-
101 => 2,
64+
101 => 1,
6565
105 => 1,
66-
107 => 1,
6766
];
6867

6968
}//end getErrorList()

0 commit comments

Comments
 (0)