當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PHP_CodeSniffer::addFixableError方法代碼示例

本文整理匯總了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
 }
開發者ID:ritters,項目名稱:mo4-coding-standard,代碼行數:42,代碼來源:VariableInDoubleQuotedStringSniff.php


注:本文中的PHP_CodeSniffer::addFixableError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。