Skip to content

Squiz/MemberVarScope: update for properties with asymmetric visibility #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
return;
}

$error = 'Scope modifier not specified for member variable "%s"';
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
if ($properties['set_scope'] === false) {
$error = 'Scope modifier not specified for member variable "%s"';
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
} else {
$error = 'Read scope modifier not specified for member variable "%s"';
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addError($error, $stackPtr, 'AsymReadMissing', $data);
}

}//end processMemberVar()

Expand Down
11 changes: 11 additions & 0 deletions src/Standards/Squiz/Tests/Scope/MemberVarScopeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ interface Base {
class PHP84FinalProperties {
final int $final;
}

class AsymVisibility {
// The read scope is public, but not specified. Error should use different error code.
public(set) $asymPublic = 'hello';
protected(set) $asymProtected = 'hello';
private(set) $asymPrivate = 'hello';

public public(set) $asymPublicPublic = 'hello';
protected(set) public $asymPublicProtected = 'hello';
protected private(set) $asymProtectedPrivate = 'hello';
}
3 changes: 3 additions & 0 deletions src/Standards/Squiz/Tests/Scope/MemberVarScopeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function getErrorList()
66 => 2,
67 => 1,
75 => 1,
80 => 1,
81 => 1,
82 => 1,
];

}//end getErrorList()
Expand Down