Skip to content

Commit b63c7ab

Browse files
authored
Merge pull request #1118 from PHPCSStandards/php-8.4/feature/pear-validvariablename-support-asym-visibility
PEAR/ValidVariableName: update for properties with asymmetric visibility
2 parents 87beff1 + 39526a5 commit b63c7ab

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
3737
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
3838
$scope = $memberProps['scope'];
3939
$scopeSpecified = $memberProps['scope_specified'];
40+
if ($scopeSpecified === false && $memberProps['set_scope'] !== false) {
41+
// Implicit `public` visibility for property with asymmetric visibility.
42+
$scopeSpecified = true;
43+
}
4044

4145
if ($memberProps['scope'] === 'private') {
4246
$isPublic = false;

src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,17 @@ $util->setLogger(
9999
private $varName = 'hello';
100100
private $_varName = 'hello';
101101
});
102+
103+
class AsymVisibility {
104+
// The read scope is public, but not specified. Enforce the naming conventions anyway.
105+
private(set) $asymPublicImplied = 'hello';
106+
private(set) $_asymPublicImplied = 'hello';
107+
108+
// The read scope is private, so these properties should be handled as private properties.
109+
private private(set) $asymPrivate = 'hello';
110+
private(set) private $_asymPrivate = 'hello';
111+
112+
// The read scope is public/protected, so these properties should be handled as public properties.
113+
public private(set) $asymPublicPrivate = 'hello';
114+
private(set) protected $_asymPrivateProtected = 'hello';
115+
}

src/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ final class ValidVariableNameUnitTest extends AbstractSniffUnitTest
3131
public function getErrorList()
3232
{
3333
return [
34-
12 => 1,
35-
17 => 1,
36-
22 => 1,
37-
92 => 1,
38-
93 => 1,
39-
94 => 1,
40-
99 => 1,
34+
12 => 1,
35+
17 => 1,
36+
22 => 1,
37+
92 => 1,
38+
93 => 1,
39+
94 => 1,
40+
99 => 1,
41+
106 => 1,
42+
109 => 1,
43+
114 => 1,
4144
];
4245

4346
}//end getErrorList()

0 commit comments

Comments
 (0)