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


PHP PHP_CodeSniffer_Reporting::prepareFileReport方法代码示例

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


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

示例1: processFile

 /**
  * Run the code sniffs over a single given file.
  *
  * Processes the file and runs the PHP_CodeSniffer sniffs to verify that it
  * conforms with the standard. Returns the processed file object, or NULL
  * if no file was processed due to error.
  *
  * @param string $file     The file to process.
  * @param string $contents The contents to parse. If NULL, the content
  *                         is taken from the file system.
  *
  * @return PHP_CodeSniffer_File
  * @throws PHP_CodeSniffer_Exception If the file could not be processed.
  * @see    _processFile()
  */
 public function processFile($file, $contents = null)
 {
     if ($contents === null && file_exists($file) === false) {
         throw new PHP_CodeSniffer_Exception("Source file {$file} does not exist");
     }
     $filePath = self::realpath($file);
     if ($filePath === false) {
         $filePath = $file;
     }
     // Before we go and spend time tokenizing this file, just check
     // to see if there is a tag up top to indicate that the whole
     // file should be ignored. It must be on one of the first two lines.
     $firstContent = $contents;
     if ($contents === null && is_readable($filePath) === true) {
         $handle = fopen($filePath, 'r');
         if ($handle !== false) {
             $firstContent = fgets($handle);
             $firstContent .= fgets($handle);
             fclose($handle);
             if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false) {
                 // We are ignoring the whole file.
                 if (PHP_CODESNIFFER_VERBOSITY > 0) {
                     echo 'Ignoring ' . basename($filePath) . PHP_EOL;
                 }
                 return null;
             }
         }
     }
     //end if
     try {
         $phpcsFile = $this->_processFile($file, $contents);
     } catch (Exception $e) {
         $trace = $e->getTrace();
         $filename = $trace[0]['args'][0];
         if (is_object($filename) === true && get_class($filename) === 'PHP_CodeSniffer_File') {
             $filename = $filename->getFilename();
         } elseif (is_numeric($filename) === true) {
             // See if we can find the PHP_CodeSniffer_File object.
             foreach ($trace as $data) {
                 if (isset($data['args'][0]) === true && $data['args'][0] instanceof PHP_CodeSniffer_File === true) {
                     $filename = $data['args'][0]->getFilename();
                 }
             }
         } elseif (is_string($filename) === false) {
             $filename = (string) $filename;
         }
         $errorMessage = '"' . $e->getMessage() . '" at ' . $e->getFile() . ':' . $e->getLine();
         $error = "An error occurred during processing; checking has been aborted. The error message was: {$errorMessage}";
         $phpcsFile = new PHP_CodeSniffer_File($filename, $this->_tokenListeners, $this->ruleset, $this);
         $phpcsFile->addError($error, null);
     }
     //end try
     $cliValues = $this->cli->getCommandLineValues();
     if (PHP_CODESNIFFER_INTERACTIVE === false) {
         // Cache the report data for this file so we can unset it to save memory.
         $this->reporting->cacheFileReport($phpcsFile, $cliValues);
         $phpcsFile->cleanUp();
         return $phpcsFile;
     }
     /*
         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 = $phpcsFile->getErrorCount() + $phpcsFile->getWarningCount();
         if ($numErrors === 0) {
             continue;
         }
         $reportClass = $this->reporting->factory('full');
         $reportData = $this->reporting->prepareFileReport($phpcsFile);
         $reportClass->generateFileReport($reportData, $phpcsFile, $cliValues['showSources'], $cliValues['reportWidth']);
         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);
                 break;
             default:
                 // Repopulate the sniffs because some of them save their state
//.........这里部分代码省略.........
开发者ID:Makiss,项目名称:test_guestbook_mvc,代码行数:101,代码来源:CodeSniffer.php


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