Mercurial > hg > cmmr2012-drupal-site
comparison vendor/squizlabs/php_codesniffer/src/Reports/Json.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 * JSON report for PHP_CodeSniffer. | |
4 * | |
5 * @author Jeffrey Fisher <jeffslofish@gmail.com> | |
6 * @author Greg Sherwood <gsherwood@squiz.net> | |
7 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) | |
8 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | |
9 */ | |
10 | |
11 namespace PHP_CodeSniffer\Reports; | |
12 | |
13 use PHP_CodeSniffer\Files\File; | |
14 | |
15 class Json implements Report | |
16 { | |
17 | |
18 | |
19 /** | |
20 * Generate a partial report for a single processed file. | |
21 * | |
22 * Function should return TRUE if it printed or stored data about the file | |
23 * and FALSE if it ignored the file. Returning TRUE indicates that the file and | |
24 * its data should be counted in the grand totals. | |
25 * | |
26 * @param array $report Prepared report data. | |
27 * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on. | |
28 * @param bool $showSources Show sources? | |
29 * @param int $width Maximum allowed line width. | |
30 * | |
31 * @return bool | |
32 */ | |
33 public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) | |
34 { | |
35 $filename = str_replace('\\', '\\\\', $report['filename']); | |
36 $filename = str_replace('"', '\"', $filename); | |
37 $filename = str_replace('/', '\/', $filename); | |
38 echo '"'.$filename.'":{'; | |
39 echo '"errors":'.$report['errors'].',"warnings":'.$report['warnings'].',"messages":['; | |
40 | |
41 $messages = ''; | |
42 foreach ($report['messages'] as $line => $lineErrors) { | |
43 foreach ($lineErrors as $column => $colErrors) { | |
44 foreach ($colErrors as $error) { | |
45 $error['message'] = str_replace("\n", '\n', $error['message']); | |
46 $error['message'] = str_replace("\r", '\r', $error['message']); | |
47 $error['message'] = str_replace("\t", '\t', $error['message']); | |
48 | |
49 $fixable = false; | |
50 if ($error['fixable'] === true) { | |
51 $fixable = true; | |
52 } | |
53 | |
54 $messagesObject = (object) $error; | |
55 $messagesObject->line = $line; | |
56 $messagesObject->column = $column; | |
57 $messagesObject->fixable = $fixable; | |
58 | |
59 $messages .= json_encode($messagesObject).","; | |
60 } | |
61 } | |
62 }//end foreach | |
63 | |
64 echo rtrim($messages, ','); | |
65 echo ']},'; | |
66 | |
67 return true; | |
68 | |
69 }//end generateFileReport() | |
70 | |
71 | |
72 /** | |
73 * Generates a JSON report. | |
74 * | |
75 * @param string $cachedData Any partial report data that was returned from | |
76 * generateFileReport during the run. | |
77 * @param int $totalFiles Total number of files processed during the run. | |
78 * @param int $totalErrors Total number of errors found during the run. | |
79 * @param int $totalWarnings Total number of warnings found during the run. | |
80 * @param int $totalFixable Total number of problems that can be fixed. | |
81 * @param bool $showSources Show sources? | |
82 * @param int $width Maximum allowed line width. | |
83 * @param bool $interactive Are we running in interactive mode? | |
84 * @param bool $toScreen Is the report being printed to screen? | |
85 * | |
86 * @return void | |
87 */ | |
88 public function generate( | |
89 $cachedData, | |
90 $totalFiles, | |
91 $totalErrors, | |
92 $totalWarnings, | |
93 $totalFixable, | |
94 $showSources=false, | |
95 $width=80, | |
96 $interactive=false, | |
97 $toScreen=true | |
98 ) { | |
99 echo '{"totals":{"errors":'.$totalErrors.',"warnings":'.$totalWarnings.',"fixable":'.$totalFixable.'},"files":{'; | |
100 echo rtrim($cachedData, ','); | |
101 echo "}}"; | |
102 | |
103 }//end generate() | |
104 | |
105 | |
106 }//end class |