diff --git a/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php b/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php index 48674b1e80..483638006a 100644 --- a/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -37,6 +37,10 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) $memberName = ltrim($tokens[$stackPtr]['content'], '$'); $scope = $memberProps['scope']; $scopeSpecified = $memberProps['scope_specified']; + if ($scopeSpecified === false && $memberProps['set_scope'] !== false) { + // Implicit `public` visibility for property with asymmetric visibility. + $scopeSpecified = true; + } if ($memberProps['scope'] === 'private') { $isPublic = false; diff --git a/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc index 3c03da3fd2..e99dda1974 100644 --- a/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ b/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -99,3 +99,17 @@ $util->setLogger( private $varName = 'hello'; private $_varName = 'hello'; }); + +class AsymVisibility { + // The read scope is public, but not specified. Enforce the naming conventions anyway. + private(set) $asymPublicImplied = 'hello'; + private(set) $_asymPublicImplied = 'hello'; + + // The read scope is private, so these properties should be handled as private properties. + private private(set) $asymPrivate = 'hello'; + private(set) private $_asymPrivate = 'hello'; + + // The read scope is public/protected, so these properties should be handled as public properties. + public private(set) $asymPublicPrivate = 'hello'; + private(set) protected $_asymPrivateProtected = 'hello'; +} diff --git a/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php b/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php index c98af3bc51..c13fb14202 100644 --- a/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -31,13 +31,16 @@ final class ValidVariableNameUnitTest extends AbstractSniffUnitTest public function getErrorList() { return [ - 12 => 1, - 17 => 1, - 22 => 1, - 92 => 1, - 93 => 1, - 94 => 1, - 99 => 1, + 12 => 1, + 17 => 1, + 22 => 1, + 92 => 1, + 93 => 1, + 94 => 1, + 99 => 1, + 106 => 1, + 109 => 1, + 114 => 1, ]; }//end getErrorList()