本文整理汇总了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
}