function ValidVariableNameSniff::processMemberVar
Same name in this branch
- 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php \Drupal\Sniffs\NamingConventions\ValidVariableNameSniff::processMemberVar()
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php \PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidVariableNameSniff::processMemberVar()
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php \PHP_CodeSniffer\Standards\Zend\Sniffs\NamingConventions\ValidVariableNameSniff::processMemberVar()
Processes class member variables.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
void
Overrides AbstractVariableSniff::processMemberVar
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PEAR/ Sniffs/ NamingConventions/ ValidVariableNameSniff.php, line 28
Class
Namespace
PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventionsCode
protected function processMemberVar(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
if ($memberProps['scope'] === 'private') {
$isPublic = false;
}
else {
$isPublic = true;
}
// If it's a private member, it must have an underscore on the front.
if ($isPublic === false && $memberName[0] !== '_') {
$error = 'Private member variable "%s" must be prefixed with an underscore';
$data = [
$memberName,
];
$phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $data);
return;
}
// If it's not a private member, it must not have an underscore on the front.
if ($isPublic === true && $scopeSpecified === true && $memberName[0] === '_') {
$error = '%s member variable "%s" must not be prefixed with an underscore';
$data = [
ucfirst($scope),
$memberName,
];
$phpcsFile->addError($error, $stackPtr, 'PublicUnderscore', $data);
return;
}
}