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


PHP PHP_CodeSniffer_Reporting::factory方法代碼示例

本文整理匯總了PHP中PHP_CodeSniffer_Reporting::factory方法的典型用法代碼示例。如果您正苦於以下問題:PHP PHP_CodeSniffer_Reporting::factory方法的具體用法?PHP PHP_CodeSniffer_Reporting::factory怎麽用?PHP PHP_CodeSniffer_Reporting::factory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHP_CodeSniffer_Reporting的用法示例。


在下文中一共展示了PHP_CodeSniffer_Reporting::factory方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testFactory

 /**
  * Test report factory method.
  *
  * @return void
  */
 public function testFactory()
 {
     $type = 'checkstyle';
     $reportClass = $this->reporting->factory($type);
     $this->assertType('PHP_CodeSniffer_Report', $reportClass);
     $this->assertType('PHP_CodeSniffer_Reports_Checkstyle', $reportClass);
     $this->setExpectedException('PHP_CodeSniffer_Exception');
     $type = 'foo';
     $reportClass = $this->reporting->factory($type);
 }
開發者ID:resid,項目名稱:PHP_CodeSniffer,代碼行數:15,代碼來源:ReportingTest.php

示例2: 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

示例3: generateFileReport

 /** {@inheritDoc} */
 public function generateFileReport($report, PHP_CodeSniffer_File $phpcsFile, $showSources = false, $width = 80)
 {
     $diff = $this->getStagedDiff();
     $changes = $this->getChanges($diff);
     $report = $this->filterReport($report, $changes);
     $reporting = new PHP_CodeSniffer_Reporting();
     $actual = $reporting->factory($this->reportType);
     return $actual->generateFileReport($report, $phpcsFile, $showSources, $width);
 }
開發者ID:morozov,項目名稱:diff-sniffer-core,代碼行數:10,代碼來源:DiffSniffer.php


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