当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer_File::addErrorOnLine方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer_File::addErrorOnLine方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::addErrorOnLine方法的具体用法?PHP PHP_CodeSniffer_File::addErrorOnLine怎么用?PHP PHP_CodeSniffer_File::addErrorOnLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer_File的用法示例。


在下文中一共展示了PHP_CodeSniffer_File::addErrorOnLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 /**
  * 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)
 {
     if ($this->_phpPath === null) {
         $this->_phpPath = PHP_CodeSniffer::getConfigData('php_path');
         if ($this->_phpPath === null) {
             // PHP_BINARY is available in PHP 5.4+.
             if (defined('PHP_BINARY') === true) {
                 $this->_phpPath = PHP_BINARY;
             } else {
                 return;
             }
         }
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = $this->_phpPath . " -l \"{$fileName}\" 2>&1";
     $output = shell_exec($cmd);
     $matches = array();
     if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/', trim($output), $matches) === 1) {
         $error = trim($matches[1]);
         $line = (int) $matches[2];
         $phpcsFile->addErrorOnLine("PHP syntax error: {$error}", $line, 'PHPSyntax');
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:squizlabs,项目名称:php_codesniffer,代码行数:34,代码来源:SyntaxSniff.php

示例2: process

 /**
  * 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)
 {
     $phpPath = PHP_CodeSniffer::getConfigData('php_path');
     if ($phpPath === null) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = "{$phpPath} -l \"{$fileName}\" 2>&1";
     $output = shell_exec($cmd);
     $matches = array();
     if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/', $output, $matches) === 1) {
         $error = trim($matches[1]);
         $line = (int) $matches[2];
         $phpcsFile->addErrorOnLine("PHP syntax error: {$error}", $line, 'PHPSyntax');
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:itliuchang,项目名称:test,代码行数:27,代码来源:SyntaxSniff.php

示例3: process

 /**
  * 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
  * @throws PHP_CodeSniffer_Exception If jslint.js could not be run
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $fileName = $phpcsFile->getFilename();
     $lintPath = PHP_CodeSniffer::getConfigData('gjslint_path');
     if ($lintPath === null) {
         return;
     }
     $cmd = "{$lintPath} --nosummary --notime --unix_mode \"{$fileName}\"";
     $msg = exec($cmd, $output, $retval);
     if (is_array($output) === false) {
         return;
     }
     foreach ($output as $finding) {
         $matches = array();
         $numMatches = preg_match('/^(.*):([0-9]+):\\(.*?([0-9]+)\\)(.*)$/', $finding, $matches);
         if ($numMatches === 0) {
             continue;
         }
         // Skip error codes we are ignoring.
         $code = $matches[3];
         if (in_array($code, $this->ignoreCodes) === true) {
             continue;
         }
         $line = (int) $matches[2];
         $error = trim($matches[4]);
         $message = 'gjslint says: (%s) %s';
         $data = array($code, $error);
         if (in_array($code, $this->errorCodes) === true) {
             $phpcsFile->addErrorOnLine($message, $line, 'ExternalToolError', $data);
         } else {
             $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool', $data);
         }
     }
     //end foreach
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:itliuchang,项目名称:test,代码行数:47,代码来源:ClosureLinterSniff.php

示例4: addFixableMissingApiAnnotation

 /**
  * @param \PHP_CodeSniffer_File $phpCsFile
  * @param int $stackPointer
  *
  * @return void
  */
 protected function addFixableMissingApiAnnotation(\PHP_CodeSniffer_File $phpCsFile, $stackPointer)
 {
     $fix = $phpCsFile->addFixableError('@api annotation is missing', $stackPointer);
     if ($fix) {
         $docCommentOpenerPosition = $phpCsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPointer);
         $firstDocCommentTagPosition = $phpCsFile->findNext(T_DOC_COMMENT_TAG, $docCommentOpenerPosition);
         if (!$firstDocCommentTagPosition) {
             $phpCsFile->addErrorOnLine('Cannot fix missing @api tag', $stackPointer);
             return;
         }
         $startPosition = $firstDocCommentTagPosition - 2;
         $phpCsFile->fixer->beginChangeset();
         $phpCsFile->fixer->addContent($startPosition, ' @api');
         $phpCsFile->fixer->addNewline($startPosition);
         $phpCsFile->fixer->addContent($startPosition, ' * ');
         $phpCsFile->fixer->addNewline($startPosition);
         $phpCsFile->fixer->addContent($startPosition, '    * ');
         $phpCsFile->fixer->endChangeset();
     }
 }
开发者ID:spryker,项目名称:code-sniffer,代码行数:26,代码来源:DocBlockApiAnnotationSniff.php


注:本文中的PHP_CodeSniffer_File::addErrorOnLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。