Chris@0: getTokens(); Chris@0: Chris@0: if ($tokens[$stackPtr]['content'][1] === '_') { Chris@0: $error = 'Property name "%s" should not be prefixed with an underscore to indicate visibility'; Chris@0: $data = array($tokens[$stackPtr]['content']); Chris@0: $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); Chris@0: } Chris@0: Chris@0: // Detect multiple properties defined at the same time. Throw an error Chris@0: // for this, but also only process the first property in the list so we don't Chris@0: // repeat errors. Chris@17: $find = Tokens::$scopeModifiers; Chris@0: $find = array_merge($find, array(T_VARIABLE, T_VAR, T_SEMICOLON)); Chris@0: $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1)); Chris@0: if ($tokens[$prev]['code'] === T_VARIABLE) { Chris@0: return; Chris@0: } Chris@0: Chris@0: if ($tokens[$prev]['code'] === T_VAR) { Chris@0: $error = 'The var keyword must not be used to declare a property'; Chris@0: $fix = $phpcsFile->addFixableError($error, $stackPtr, 'VarUsed'); Chris@0: if ($fix === true) { Chris@0: $phpcsFile->fixer->replaceToken($prev, 'public'); Chris@0: } Chris@0: } Chris@0: Chris@0: $next = $phpcsFile->findNext(array(T_VARIABLE, T_SEMICOLON), ($stackPtr + 1)); Chris@0: if ($tokens[$next]['code'] === T_VARIABLE) { Chris@0: $error = 'There must not be more than one property declared per statement'; Chris@0: $phpcsFile->addError($error, $stackPtr, 'Multiple'); Chris@0: } Chris@0: Chris@17: $modifier = $phpcsFile->findPrevious(Tokens::$scopeModifiers, $stackPtr); Chris@0: if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) { Chris@0: $error = 'Visibility must be declared on property "%s"'; Chris@0: $data = array($tokens[$stackPtr]['content']); Chris@0: $phpcsFile->addError($error, $stackPtr, 'ScopeMissing', $data); Chris@0: } Chris@0: Chris@0: }//end processMemberVar() Chris@0: Chris@0: Chris@0: /** Chris@0: * Processes normal variables. Chris@0: * Chris@17: * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. Chris@17: * @param int $stackPtr The position where the token was found. Chris@0: * Chris@0: * @return void Chris@0: */ Chris@17: protected function processVariable(File $phpcsFile, $stackPtr) Chris@0: { Chris@0: /* Chris@0: We don't care about normal variables. Chris@0: */ Chris@0: Chris@0: }//end processVariable() Chris@0: Chris@0: Chris@0: /** Chris@0: * Processes variables in double quoted strings. Chris@0: * Chris@17: * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. Chris@17: * @param int $stackPtr The position where the token was found. Chris@0: * Chris@0: * @return void Chris@0: */ Chris@17: protected function processVariableInString(File $phpcsFile, $stackPtr) Chris@0: { Chris@0: /* Chris@0: We don't care about normal variables. Chris@0: */ Chris@0: Chris@0: }//end processVariableInString() Chris@0: Chris@0: Chris@0: }//end class