本文整理匯總了PHP中PHP_CodeSniffer::addFixableError方法的典型用法代碼示例。如果您正苦於以下問題:PHP PHP_CodeSniffer::addFixableError方法的具體用法?PHP PHP_CodeSniffer::addFixableError怎麽用?PHP PHP_CodeSniffer::addFixableError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PHP_CodeSniffer
的用法示例。
在下文中一共展示了PHP_CodeSniffer::addFixableError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: process
/**
* Called when one of the token types that this sniff is listening for
* is found.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
* token was found.
* @param int $stackPtr The position in the PHP_CodeSniffer
* file's token stack where the token
* was found.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->_phpCsFile = $phpcsFile;
$varRegExp = '/\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/';
$tokens = $phpcsFile->getTokens();
$content = $tokens[$stackPtr]['content'];
$matches = array();
if (preg_match_all($varRegExp, $content, $matches, PREG_OFFSET_CAPTURE) === 0) {
return;
}
foreach ($matches as $match) {
foreach ($match as $info) {
list($var, $pos) = $info;
if ($pos === 1 || $content[$pos - 1] !== '{') {
if (strpos(substr($content, 0, $pos), '{') > 0 && strpos(substr($content, 0, $pos), '}') === false) {
continue;
}
$this->_searchForBackslashes($content, $pos);
$fix = $this->_phpCsFile->addFixableError(sprintf('must surround variable %s with { }', $var), $stackPtr, 'NotSurroundedWithBraces');
if ($fix === true) {
$correctVariable = $this->_surroundVariableWithBraces($content, $pos, $var);
$this->_fixPhpCsFile($stackPtr, $correctVariable);
}
}
//end if
}
//end foreach
}
//end foreach
}