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


PHP File::addErrorOnLine方法代码示例

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


在下文中一共展示了File::addErrorOnLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(File $phpcsFile, $stackPtr)
 {
     if ($this->phpPath === null) {
         $this->phpPath = Config::getExecutablePath('php');
         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:thekabal,项目名称:tki,代码行数:34,代码来源:SyntaxSniff.php

示例2: 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(File $phpcsFile, $stackPtr)
 {
     $lintPath = Config::getExecutablePath('gjslint');
     if ($lintPath === null) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     $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:thekabal,项目名称:tki,代码行数:47,代码来源:ClosureLinterSniff.php

示例3: processFile

 /**
  * Processes a single file, including checking and fixing.
  *
  * @param \PHP_CodeSniffer\Files\File $file The file to be processed.
  *
  * @return void
  */
 private function processFile($file)
 {
     if (PHP_CODESNIFFER_VERBOSITY > 0) {
         $startTime = microtime(true);
         echo 'Processing ' . basename($file->path) . ' ';
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
             echo PHP_EOL;
         }
     }
     try {
         $file->process();
         if (PHP_CODESNIFFER_VERBOSITY > 0) {
             $timeTaken = (microtime(true) - $startTime) * 1000;
             if ($timeTaken < 1000) {
                 $timeTaken = round($timeTaken);
                 echo "DONE in {$timeTaken}ms";
             } else {
                 $timeTaken = round($timeTaken / 1000, 2);
                 echo "DONE in {$timeTaken} secs";
             }
             if (PHP_CODESNIFFER_CBF === true) {
                 $errors = $file->getFixableCount();
                 echo " ({$errors} fixable violations)" . PHP_EOL;
             } else {
                 $errors = $file->getErrorCount();
                 $warnings = $file->getWarningCount();
                 echo " ({$errors} errors, {$warnings} warnings)" . PHP_EOL;
             }
         }
     } catch (\Exception $e) {
         $error = 'An error occurred during processing; checking has been aborted. The error message was: ' . $e->getMessage();
         $file->addErrorOnLine($error, 1, 'Internal.Exception');
     }
     //end try
     $this->reporter->cacheFileReport($file, $this->config);
     // Clean up the file to save (a lot of) memory.
     $file->cleanUp();
     if ($this->config->interactive === true) {
         /*
             Running interactively.
             Print the error report for the current file and then wait for user input.
         */
         // Get current violations and then clear the list to make sure
         // we only print violations for a single file each time.
         $numErrors = null;
         while ($numErrors !== 0) {
             $numErrors = $file->getErrorCount() + $file->getWarningCount();
             if ($numErrors === 0) {
                 continue;
             }
             $this->reporter->printReport('full');
             echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
             $input = fgets(STDIN);
             $input = trim($input);
             switch ($input) {
                 case 's':
                     break 2;
                 case 'q':
                     exit(0);
                 default:
                     // Repopulate the sniffs because some of them save their state
                     // and only clear it when the file changes, but we are rechecking
                     // the same file.
                     $file->ruleset->populateTokenListeners();
                     $file->reloadContent();
                     $file->process();
                     $this->reporter->cacheFileReport($file, $this->config);
                     break;
             }
         }
         //end while
     }
     //end if
 }
开发者ID:thekabal,项目名称:tki,代码行数:81,代码来源:Runner.php


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