/** * Processes the tokens that this sniff is interested in. * * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. * @param int $stackPtr The position in the stack where * the token was found. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $methodName = $phpcsFile->getDeclarationName($stackPtr); $methodProps = $phpcsFile->getMethodProperties($stackPtr); if ($methodProps['is_static']) { if (!PHP_CodeSniffer_Standards_Silverstripe_SilverstripeCodingStandard::isLowerCaseWithUnderScore($methodName)) { $error = "Function name \"{$methodName}\" is invalid Static methods should be in lowercase_with_underscores() format."; $phpcsFile->addError($error, $stackPtr); } } else { } }
/** * Processes class member variables. * * @param PHP_CodeSniffer_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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $varName = ltrim($tokens[$stackPtr]['content'], '$'); $memberProps = $phpcsFile->getMemberProperties($stackPtr); $public = $memberProps['scope'] !== 'private'; if ($memberProps['is_static']) { if (!PHP_CodeSniffer_Standards_Silverstripe_SilverstripeCodingStandard::isLowerCaseWithUnderScore($varName)) { $error = "Variable name \"{$varName}\" is invalid Static variables should be self::lowercase_with_underscores() format."; $phpcsFile->addError($error, $stackPtr); return; } } else { if (PHP_CodeSniffer::isCamelCaps($varName, false, $public, false) === false) { $error = "Variable \"{$varName}\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } } }