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


PHP File::getFixableCount方法代码示例

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


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

示例1: generateFileReport

 /**
  * Generate a partial report for a single processed file.
  *
  * Function should return TRUE if it printed or stored data about the file
  * and FALSE if it ignored the file. Returning TRUE indicates that the file and
  * its data should be counted in the grand totals.
  *
  * @param array                 $report      Prepared report data.
  * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
  * @param bool                  $showSources Show sources?
  * @param int                   $width       Maximum allowed line width.
  *
  * @return bool
  */
 public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
 {
     $errors = $phpcsFile->getFixableCount();
     if ($errors !== 0) {
         if (PHP_CODESNIFFER_VERBOSITY > 0) {
             ob_end_clean();
             $startTime = microtime(true);
             echo "\t=> Fixing file: {$errors}/{$errors} violations remaining";
         }
         $fixed = $phpcsFile->fixer->fixFile();
     }
     if ($phpcsFile->config->stdin === true) {
         // Replacing STDIN, so output current file to STDOUT
         // even if nothing was fixed. Exit here because we
         // can't process any more than 1 file in this setup.
         echo $phpcsFile->fixer->getContents();
         ob_end_flush();
         exit(1);
     }
     if ($errors === 0) {
         return false;
     }
     if (PHP_CODESNIFFER_VERBOSITY > 0) {
         if ($fixed === false) {
             echo 'ERROR';
         } else {
             echo 'DONE';
         }
         $timeTaken = (microtime(true) - $startTime) * 1000;
         if ($timeTaken < 1000) {
             $timeTaken = round($timeTaken);
             echo " in {$timeTaken}ms" . PHP_EOL;
         } else {
             $timeTaken = round($timeTaken / 1000, 2);
             echo " in {$timeTaken} secs" . PHP_EOL;
         }
     }
     if ($fixed === true) {
         $newFilename = $report['filename'] . $phpcsFile->config->suffix;
         $newContent = $phpcsFile->fixer->getContents();
         file_put_contents($newFilename, $newContent);
         if (PHP_CODESNIFFER_VERBOSITY > 0) {
             if ($newFilename === $report['filename']) {
                 echo "\t=> File was overwritten" . PHP_EOL;
             } else {
                 echo "\t=> Fixed file written to " . basename($newFilename) . PHP_EOL;
             }
         }
     }
     if (PHP_CODESNIFFER_VERBOSITY > 0) {
         ob_start();
     }
     $errorCount = $phpcsFile->getErrorCount();
     $warningCount = $phpcsFile->getWarningCount();
     $fixableCount = $phpcsFile->getFixableCount();
     $fixedCount = $errors - $fixableCount;
     echo $report['filename'] . ">>{$errorCount}>>{$warningCount}>>{$fixableCount}>>{$fixedCount}" . PHP_EOL;
     return $fixed;
 }
开发者ID:thekabal,项目名称:tki,代码行数:73,代码来源:Cbf.php

示例2: generateFileReport

 /**
  * Generate a partial report for a single processed file.
  *
  * Function should return TRUE if it printed or stored data about the file
  * and FALSE if it ignored the file. Returning TRUE indicates that the file and
  * its data should be counted in the grand totals.
  *
  * @param array                 $report      Prepared report data.
  * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
  * @param bool                  $showSources Show sources?
  * @param int                   $width       Maximum allowed line width.
  *
  * @return bool
  */
 public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
 {
     $errors = $phpcsFile->getFixableCount();
     if ($errors === 0) {
         return false;
     }
     $phpcsFile->disableCaching();
     $tokens = $phpcsFile->getTokens();
     if (empty($tokens) === true) {
         if (PHP_CODESNIFFER_VERBOSITY === 1) {
             $startTime = microtime(true);
             echo 'DIFF report is parsing ' . basename($report['filename']) . ' ';
         } else {
             if (PHP_CODESNIFFER_VERBOSITY > 1) {
                 echo 'DIFF report is forcing parse of ' . $report['filename'] . PHP_EOL;
             }
         }
         $phpcsFile->parse();
         if (PHP_CODESNIFFER_VERBOSITY === 1) {
             $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";
             }
             echo PHP_EOL;
         }
         $phpcsFile->fixer->startFile($phpcsFile);
     }
     //end if
     if (PHP_CODESNIFFER_VERBOSITY > 1) {
         ob_end_clean();
         echo "\t*** START FILE FIXING ***" . PHP_EOL;
     }
     $fixed = $phpcsFile->fixer->fixFile();
     if (PHP_CODESNIFFER_VERBOSITY > 1) {
         echo "\t*** END FILE FIXING ***" . PHP_EOL;
         ob_start();
     }
     if ($fixed === false) {
         return false;
     }
     $diff = $phpcsFile->fixer->generateDiff();
     if ($diff === '') {
         // Nothing to print.
         return false;
     }
     echo $diff . PHP_EOL;
     return true;
 }
开发者ID:thekabal,项目名称:tki,代码行数:66,代码来源:Diff.php

示例3: fixFile

 /**
  * Attempt to fix the file by processing it until no fixes are made.
  *
  * @return boolean
  */
 public function fixFile()
 {
     $fixable = $this->currentFile->getFixableCount();
     if ($fixable === 0) {
         // Nothing to fix.
         return false;
     }
     $stdin = false;
     if (empty($this->currentFile->config->files) === true) {
         $stdin = true;
     }
     $this->enabled = true;
     $this->loops = 0;
     while ($this->loops < 50) {
         ob_start();
         // Only needed once file content has changed.
         $contents = $this->getContents();
         if (PHP_CODESNIFFER_VERBOSITY > 2) {
             @ob_end_clean();
             echo '---START FILE CONTENT---' . PHP_EOL;
             $lines = explode($this->currentFile->eolChar, $contents);
             $max = strlen(count($lines));
             foreach ($lines as $lineNum => $line) {
                 $lineNum++;
                 echo str_pad($lineNum, $max, ' ', STR_PAD_LEFT) . '|' . $line . PHP_EOL;
             }
             echo '--- END FILE CONTENT ---' . PHP_EOL;
             ob_start();
         }
         $this->inConflict = false;
         $this->currentFile->ruleset->populateTokenListeners();
         $this->currentFile->setContent($contents);
         $this->currentFile->process();
         ob_end_clean();
         $this->loops++;
         if (PHP_CODESNIFFER_CBF === true && PHP_CODESNIFFER_VERBOSITY > 0) {
             echo "\r" . str_repeat(' ', 80) . "\r";
             echo "\t=> Fixing file: {$this->numFixes}/{$fixable} violations remaining [made {$this->loops} pass";
             if ($this->loops > 1) {
                 echo 'es';
             }
             echo ']... ';
         }
         if ($this->numFixes === 0 && $this->inConflict === false) {
             // Nothing left to do.
             break;
         } else {
             if (PHP_CODESNIFFER_VERBOSITY > 1) {
                 echo "\t* fixed {$this->numFixes} violations, starting loop " . ($this->loops + 1) . ' *' . PHP_EOL;
             }
         }
     }
     //end while
     $this->enabled = false;
     if ($this->numFixes > 0) {
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
             @ob_end_clean();
             echo "\t*** Reached maximum number of loops with {$this->numFixes} violations left unfixed ***" . PHP_EOL;
             ob_start();
         }
         return false;
     }
     return true;
 }
开发者ID:thekabal,项目名称:tki,代码行数:69,代码来源:Fixer.php

示例4: prepareFileReport

 /**
  * Generate summary information to be used during report generation.
  *
  * @param \PHP_CodeSniffer\Files\File $phpcsFile The file that has been processed.
  *
  * @return array
  */
 public function prepareFileReport(File $phpcsFile)
 {
     $report = array('filename' => Common::stripBasepath($phpcsFile->getFilename(), $this->config->basepath), 'errors' => $phpcsFile->getErrorCount(), 'warnings' => $phpcsFile->getWarningCount(), 'fixable' => $phpcsFile->getFixableCount(), 'messages' => array());
     if ($report['errors'] === 0 && $report['warnings'] === 0) {
         // Prefect score!
         return $report;
     }
     if ($this->config->recordErrors === false) {
         $message = 'Errors are not being recorded but this report requires error messages. ';
         $message .= 'This report will not show the correct information.';
         $report['messages'][1][1] = array(array('message' => $message, 'source' => 'Internal.RecordErrors', 'severity' => 5, 'fixable' => false, 'type' => 'ERROR'));
         return $report;
     }
     $errors = array();
     // Merge errors and warnings.
     foreach ($phpcsFile->getErrors() as $line => $lineErrors) {
         foreach ($lineErrors as $column => $colErrors) {
             $newErrors = array();
             foreach ($colErrors as $data) {
                 $newErrors[] = array('message' => $data['message'], 'source' => $data['source'], 'severity' => $data['severity'], 'fixable' => $data['fixable'], 'type' => 'ERROR');
             }
             $errors[$line][$column] = $newErrors;
         }
         ksort($errors[$line]);
     }
     //end foreach
     foreach ($phpcsFile->getWarnings() as $line => $lineWarnings) {
         foreach ($lineWarnings as $column => $colWarnings) {
             $newWarnings = array();
             foreach ($colWarnings as $data) {
                 $newWarnings[] = array('message' => $data['message'], 'source' => $data['source'], 'severity' => $data['severity'], 'fixable' => $data['fixable'], 'type' => 'WARNING');
             }
             if (isset($errors[$line]) === false) {
                 $errors[$line] = array();
             }
             if (isset($errors[$line][$column]) === true) {
                 $errors[$line][$column] = array_merge($newWarnings, $errors[$line][$column]);
             } else {
                 $errors[$line][$column] = $newWarnings;
             }
         }
         //end foreach
         ksort($errors[$line]);
     }
     //end foreach
     ksort($errors);
     $report['messages'] = $errors;
     return $report;
 }
开发者ID:thekabal,项目名称:tki,代码行数:56,代码来源:Reporter.php

示例5: printProgress

 /**
  * Print progress information for a single processed file.
  *
  * @param File $file         The file that was processed.
  * @param int  $numFiles     The total number of files to process.
  * @param int  $numProcessed The number of files that have been processed,
  *                           including this one.
  *
  * @return void
  */
 function printProgress($file, $numFiles, $numProcessed)
 {
     if (PHP_CODESNIFFER_VERBOSITY > 0 || $this->config->showProgress === false) {
         return;
     }
     // Show progress information.
     if ($file->ignored === true) {
         echo 'S';
     } else {
         $errors = $file->getErrorCount();
         $warnings = $file->getWarningCount();
         $fixable = $file->getFixableCount();
         $fixed = $file->getFixedCount();
         if (PHP_CODESNIFFER_CBF === true) {
             // Files with fixed errors or warnings are F (green).
             // Files with unfixable errors or warnings are E (red).
             // Files with no errors or warnings are . (black).
             if ($fixable > 0) {
                 if ($this->config->colors === true) {
                     echo "[31m";
                 }
                 echo 'E';
                 if ($this->config->colors === true) {
                     echo "[0m";
                 }
             } else {
                 if ($fixed > 0) {
                     if ($this->config->colors === true) {
                         echo "[32m";
                     }
                     echo 'F';
                     if ($this->config->colors === true) {
                         echo "[0m";
                     }
                 } else {
                     echo '.';
                 }
             }
             //end if
         } else {
             // Files with errors are E (red).
             // Files with fixable errors are E (green).
             // Files with warnings are W (yellow).
             // Files with fixable warnings are W (green).
             // Files with no errors or warnings are . (black).
             if ($errors > 0) {
                 if ($this->config->colors === true) {
                     if ($fixable > 0) {
                         echo "[32m";
                     } else {
                         echo "[31m";
                     }
                 }
                 echo 'E';
                 if ($this->config->colors === true) {
                     echo "[0m";
                 }
             } else {
                 if ($warnings > 0) {
                     if ($this->config->colors === true) {
                         if ($fixable > 0) {
                             echo "[32m";
                         } else {
                             echo "[33m";
                         }
                     }
                     echo 'W';
                     if ($this->config->colors === true) {
                         echo "[0m";
                     }
                 } else {
                     echo '.';
                 }
             }
             //end if
         }
         //end if
     }
     //end if
     if ($numProcessed % 60 === 0) {
         $padding = strlen($numFiles) - strlen($numProcessed);
         echo str_repeat(' ', $padding);
         $percent = round($numProcessed / $numFiles * 100);
         echo " {$numProcessed} / {$numFiles} ({$percent}%)" . PHP_EOL;
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:96,代码来源:Runner.php


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