/** * Processes this test, when one of its tokens is encountered. * * @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 */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['code'] === T_IF) { $openParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, null); $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer']; $nextToken = $phpcsFile->findNext(T_WHITESPACE, $closeParenthesis + 1, null, true); if (in_array($tokens[$nextToken]['code'], array(T_RETURN, T_BREAK, T_CONTINUE, T_THROW, T_STRING, T_VARIABLE, T_UNSET), true)) { return; } } parent::process($phpcsFile, $stackPtr); }
/** * Processes this test, when one of its tokens is encountered. * * @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 */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); // Check for the alternate syntax for control structures with colons (:). if (isset($tokens[$stackPtr]['parenthesis_closer'])) { $start = $tokens[$stackPtr]['parenthesis_closer']; } else { $start = $stackPtr; } $scopeOpener = $phpcsFile->findNext(T_WHITESPACE, $start + 1, null, true); if ($tokens[$scopeOpener]['code'] === T_COLON) { return; } parent::process($phpcsFile, $stackPtr); }
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { // Lines which will be ignored (without whitespaces) $ignoreLines = array("if(!defined('sugarEntry'))define('sugarEntry',true);" => true); $tokens = $phpcsFile->getTokens(); $codeStr = ''; for ($i = $stackPtr; $i < $phpcsFile->numTokens; $i++) { if ($tokens[$i]['line'] == $tokens[$stackPtr]['line']) { if ($tokens[$i]['code'] !== T_WHITESPACE) { $codeStr .= $tokens[$i]['content']; } } else { break; } } if (!isset($ignoreLines[$codeStr])) { parent::process($phpcsFile, $stackPtr); } }