class LowercaseDeclarationSniff
Hierarchy
- class \PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\LowercaseDeclarationSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of LowercaseDeclarationSniff
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ ControlStructures/ LowercaseDeclarationSniff.php, line 15
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructuresView source
class LowercaseDeclarationSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register() {
return [
T_IF,
T_ELSE,
T_ELSEIF,
T_FOREACH,
T_FOR,
T_DO,
T_SWITCH,
T_WHILE,
T_TRY,
T_CATCH,
T_MATCH,
];
}
//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @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
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$content = $tokens[$stackPtr]['content'];
$contentLc = strtolower($content);
if ($content !== $contentLc) {
$error = '%s keyword must be lowercase; expected "%s" but found "%s"';
$data = [
strtoupper($content),
$contentLc,
$content,
];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'FoundUppercase', $data);
if ($fix === true) {
$phpcsFile->fixer
->replaceToken($stackPtr, $contentLc);
}
}
}
//end process()
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
LowercaseDeclarationSniff::process | public | function | Processes this test, when one of its tokens is encountered. | Overrides Sniff::process |
LowercaseDeclarationSniff::register | public | function | Returns an array of tokens this test wants to listen for. | Overrides Sniff::register |