8 use PHP_CodeSniffer\Sniffs\Sniff;
9 use PHP_CodeSniffer\Files\File;
35 public function register()
43 public function process(File $phpcsFile, $stackPtr)
45 $tokens = $phpcsFile->getTokens();
46 $currentToken =
$tokens[$stackPtr];
48 $nextColon = $phpcsFile->findNext(T_COLON, $stackPtr);
49 $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
50 if ((
false === $nextColon) || (
false === $nextSemicolon)) {
54 $isVariableDeclaration = ($currentToken[
'line'] ===
$tokens[$nextColon][
'line'])
55 && ($currentToken[
'line'] ===
$tokens[$nextSemicolon][
'line'])
56 && (T_STRING ===
$tokens[$stackPtr + 1][
'code'])
57 && (T_COLON ===
$tokens[$stackPtr + 2][
'code']);
59 if (!$isVariableDeclaration) {
63 $classBefore = $phpcsFile->findPrevious(T_STYLE, $stackPtr);
64 if (
false !== $classBefore) {
66 'Variable declaration located not in the beginning of general comments',
72 $variableName =
$tokens[$stackPtr + 1][
'content'];
73 if (preg_match(
'/[A-Z]/', $variableName)) {
75 'Variable declaration contains uppercase symbols',
process(File $phpcsFile, $stackPtr)