Skip to content

Commit 8fab89f

Browse files
authored
Merge pull request #1122 from PHPCSStandards/php-8.4/feature/squiz-membervarscope-support-asym-visibility
Squiz/MemberVarScope: update for properties with asymmetric visibility
2 parents d4e23ce + 622ac74 commit 8fab89f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
3333
return;
3434
}
3535

36-
$error = 'Scope modifier not specified for member variable "%s"';
37-
$data = [$tokens[$stackPtr]['content']];
38-
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
36+
if ($properties['set_scope'] === false) {
37+
$error = 'Scope modifier not specified for member variable "%s"';
38+
$data = [$tokens[$stackPtr]['content']];
39+
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
40+
} else {
41+
$error = 'Read scope modifier not specified for member variable "%s"';
42+
$data = [$tokens[$stackPtr]['content']];
43+
$phpcsFile->addError($error, $stackPtr, 'AsymReadMissing', $data);
44+
}
3945

4046
}//end processMemberVar()
4147

src/Standards/Squiz/Tests/Scope/MemberVarScopeUnitTest.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,14 @@ interface Base {
7474
class PHP84FinalProperties {
7575
final int $final;
7676
}
77+
78+
class AsymVisibility {
79+
// The read scope is public, but not specified. Error should use different error code.
80+
public(set) $asymPublic = 'hello';
81+
protected(set) $asymProtected = 'hello';
82+
private(set) $asymPrivate = 'hello';
83+
84+
public public(set) $asymPublicPublic = 'hello';
85+
protected(set) public $asymPublicProtected = 'hello';
86+
protected private(set) $asymProtectedPrivate = 'hello';
87+
}

src/Standards/Squiz/Tests/Scope/MemberVarScopeUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public function getErrorList()
4040
66 => 2,
4141
67 => 1,
4242
75 => 1,
43+
80 => 1,
44+
81 => 1,
45+
82 => 1,
4346
];
4447

4548
}//end getErrorList()

0 commit comments

Comments
 (0)