class ValidVariableNameSniff
Same name in this branch
- 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php \Drupal\Sniffs\NamingConventions\ValidVariableNameSniff
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php \PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidVariableNameSniff
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php \PHP_CodeSniffer\Standards\Zend\Sniffs\NamingConventions\ValidVariableNameSniff
Hierarchy
- class \PHP_CodeSniffer\Sniffs\AbstractScopeSniff implements \PHP_CodeSniffer\Sniffs\Sniff
- class \PHP_CodeSniffer\Sniffs\AbstractVariableSniff extends \PHP_CodeSniffer\Sniffs\AbstractScopeSniff
- class \PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidVariableNameSniff extends \PHP_CodeSniffer\Sniffs\AbstractVariableSniff
- class \PHP_CodeSniffer\Sniffs\AbstractVariableSniff extends \PHP_CodeSniffer\Sniffs\AbstractScopeSniff
Expanded class hierarchy of ValidVariableNameSniff
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PEAR/ Sniffs/ NamingConventions/ ValidVariableNameSniff.php, line 15
Namespace
PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventionsView source
class ValidVariableNameSniff extends AbstractVariableSniff {
/**
* Processes class member variables.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
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;
}
}
//end processMemberVar()
/**
* Processes normal variables.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariable(File $phpcsFile, $stackPtr) {
/*
We don't care about normal variables.
*/
}
//end processVariable()
/**
* Processes variables in double quoted strings.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariableInString(File $phpcsFile, $stackPtr) {
/*
We don't care about normal variables.
*/
}
//end processVariableInString()
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AbstractScopeSniff::$listenOutside | private | property | True if this test should fire on tokens outside of the scope. | |
AbstractScopeSniff::$scopeTokens | private | property | The type of scope opener tokens that this test wishes to listen to. | |
AbstractScopeSniff::$tokens | private | property | The token types that this test wishes to listen to within the scope. | |
AbstractScopeSniff::process | final public | function | Processes the tokens that this test is listening for. | Overrides Sniff::process |
AbstractScopeSniff::register | final public | function | The method that is called to register the tokens this test wishes to listen to. |
Overrides Sniff::register |
AbstractVariableSniff::$phpReservedVars | protected | property | List of PHP Reserved variables. | |
AbstractVariableSniff::processTokenOutsideScope | final protected | function | Processes the token outside the scope in the file. | Overrides AbstractScopeSniff::processTokenOutsideScope |
AbstractVariableSniff::processTokenWithinScope | final protected | function | Processes the token in the specified PHP_CodeSniffer\Files\File. | Overrides AbstractScopeSniff::processTokenWithinScope |
AbstractVariableSniff::__construct | public | function | Constructs an AbstractVariableTest. | Overrides AbstractScopeSniff::__construct |
ValidVariableNameSniff::processMemberVar | protected | function | Processes class member variables. | Overrides AbstractVariableSniff::processMemberVar |
ValidVariableNameSniff::processVariable | protected | function | Processes normal variables. | Overrides AbstractVariableSniff::processVariable |
ValidVariableNameSniff::processVariableInString | protected | function | Processes variables in double quoted strings. | Overrides AbstractVariableSniff::processVariableInString |