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