annotate vendor/squizlabs/php_codesniffer/src/Reports/Diff.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
rev   line source
Chris@4 1 <?php
Chris@4 2 /**
Chris@4 3 * Diff report for PHP_CodeSniffer.
Chris@4 4 *
Chris@4 5 * @author Greg Sherwood <gsherwood@squiz.net>
Chris@4 6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Chris@4 7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
Chris@4 8 */
Chris@4 9
Chris@4 10 namespace PHP_CodeSniffer\Reports;
Chris@4 11
Chris@4 12 use PHP_CodeSniffer\Files\File;
Chris@4 13
Chris@4 14 class Diff implements Report
Chris@4 15 {
Chris@4 16
Chris@4 17
Chris@4 18 /**
Chris@4 19 * Generate a partial report for a single processed file.
Chris@4 20 *
Chris@4 21 * Function should return TRUE if it printed or stored data about the file
Chris@4 22 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
Chris@4 23 * its data should be counted in the grand totals.
Chris@4 24 *
Chris@4 25 * @param array $report Prepared report data.
Chris@4 26 * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
Chris@4 27 * @param bool $showSources Show sources?
Chris@4 28 * @param int $width Maximum allowed line width.
Chris@4 29 *
Chris@4 30 * @return bool
Chris@4 31 */
Chris@4 32 public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
Chris@4 33 {
Chris@4 34 $errors = $phpcsFile->getFixableCount();
Chris@4 35 if ($errors === 0) {
Chris@4 36 return false;
Chris@4 37 }
Chris@4 38
Chris@4 39 $phpcsFile->disableCaching();
Chris@4 40 $tokens = $phpcsFile->getTokens();
Chris@4 41 if (empty($tokens) === true) {
Chris@4 42 if (PHP_CODESNIFFER_VERBOSITY === 1) {
Chris@4 43 $startTime = microtime(true);
Chris@4 44 echo 'DIFF report is parsing '.basename($report['filename']).' ';
Chris@4 45 } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 46 echo 'DIFF report is forcing parse of '.$report['filename'].PHP_EOL;
Chris@4 47 }
Chris@4 48
Chris@4 49 $phpcsFile->parse();
Chris@4 50
Chris@4 51 if (PHP_CODESNIFFER_VERBOSITY === 1) {
Chris@4 52 $timeTaken = ((microtime(true) - $startTime) * 1000);
Chris@4 53 if ($timeTaken < 1000) {
Chris@4 54 $timeTaken = round($timeTaken);
Chris@4 55 echo "DONE in {$timeTaken}ms";
Chris@4 56 } else {
Chris@4 57 $timeTaken = round(($timeTaken / 1000), 2);
Chris@4 58 echo "DONE in $timeTaken secs";
Chris@4 59 }
Chris@4 60
Chris@4 61 echo PHP_EOL;
Chris@4 62 }
Chris@4 63
Chris@4 64 $phpcsFile->fixer->startFile($phpcsFile);
Chris@4 65 }//end if
Chris@4 66
Chris@4 67 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 68 ob_end_clean();
Chris@4 69 echo "\t*** START FILE FIXING ***".PHP_EOL;
Chris@4 70 }
Chris@4 71
Chris@4 72 $fixed = $phpcsFile->fixer->fixFile();
Chris@4 73
Chris@4 74 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 75 echo "\t*** END FILE FIXING ***".PHP_EOL;
Chris@4 76 ob_start();
Chris@4 77 }
Chris@4 78
Chris@4 79 if ($fixed === false) {
Chris@4 80 return false;
Chris@4 81 }
Chris@4 82
Chris@4 83 $diff = $phpcsFile->fixer->generateDiff();
Chris@4 84 if ($diff === '') {
Chris@4 85 // Nothing to print.
Chris@4 86 return false;
Chris@4 87 }
Chris@4 88
Chris@4 89 echo $diff.PHP_EOL;
Chris@4 90 return true;
Chris@4 91
Chris@4 92 }//end generateFileReport()
Chris@4 93
Chris@4 94
Chris@4 95 /**
Chris@4 96 * Prints all errors and warnings for each file processed.
Chris@4 97 *
Chris@4 98 * @param string $cachedData Any partial report data that was returned from
Chris@4 99 * generateFileReport during the run.
Chris@4 100 * @param int $totalFiles Total number of files processed during the run.
Chris@4 101 * @param int $totalErrors Total number of errors found during the run.
Chris@4 102 * @param int $totalWarnings Total number of warnings found during the run.
Chris@4 103 * @param int $totalFixable Total number of problems that can be fixed.
Chris@4 104 * @param bool $showSources Show sources?
Chris@4 105 * @param int $width Maximum allowed line width.
Chris@4 106 * @param bool $interactive Are we running in interactive mode?
Chris@4 107 * @param bool $toScreen Is the report being printed to screen?
Chris@4 108 *
Chris@4 109 * @return void
Chris@4 110 */
Chris@4 111 public function generate(
Chris@4 112 $cachedData,
Chris@4 113 $totalFiles,
Chris@4 114 $totalErrors,
Chris@4 115 $totalWarnings,
Chris@4 116 $totalFixable,
Chris@4 117 $showSources=false,
Chris@4 118 $width=80,
Chris@4 119 $interactive=false,
Chris@4 120 $toScreen=true
Chris@4 121 ) {
Chris@4 122 echo $cachedData;
Chris@4 123 if ($toScreen === true && $cachedData !== '') {
Chris@4 124 echo PHP_EOL;
Chris@4 125 }
Chris@4 126
Chris@4 127 }//end generate()
Chris@4 128
Chris@4 129
Chris@4 130 }//end class