Chris@0
|
1 <?php
|
Chris@0
|
2 /**
|
Chris@0
|
3 * Checkstyle report for PHP_CodeSniffer.
|
Chris@0
|
4 *
|
Chris@0
|
5 * PHP version 5
|
Chris@0
|
6 *
|
Chris@0
|
7 * @category PHP
|
Chris@0
|
8 * @package PHP_CodeSniffer
|
Chris@0
|
9 * @author Gabriele Santini <gsantini@sqli.com>
|
Chris@0
|
10 * @author Greg Sherwood <gsherwood@squiz.net>
|
Chris@0
|
11 * @copyright 2009-2014 SQLI <www.sqli.com>
|
Chris@0
|
12 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
|
Chris@0
|
13 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
Chris@0
|
14 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
15 */
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Checkstyle report for PHP_CodeSniffer.
|
Chris@0
|
19 *
|
Chris@0
|
20 * PHP version 5
|
Chris@0
|
21 *
|
Chris@0
|
22 * @category PHP
|
Chris@0
|
23 * @package PHP_CodeSniffer
|
Chris@0
|
24 * @author Gabriele Santini <gsantini@sqli.com>
|
Chris@0
|
25 * @author Greg Sherwood <gsherwood@squiz.net>
|
Chris@0
|
26 * @copyright 2009-2014 SQLI <www.sqli.com>
|
Chris@0
|
27 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
|
Chris@0
|
28 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
Chris@0
|
29 * @version Release: @package_version@
|
Chris@0
|
30 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
31 */
|
Chris@0
|
32 class PHP_CodeSniffer_Reports_Checkstyle implements PHP_CodeSniffer_Report
|
Chris@0
|
33 {
|
Chris@0
|
34
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * Generate a partial report for a single processed file.
|
Chris@0
|
38 *
|
Chris@0
|
39 * Function should return TRUE if it printed or stored data about the file
|
Chris@0
|
40 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
|
Chris@0
|
41 * its data should be counted in the grand totals.
|
Chris@0
|
42 *
|
Chris@0
|
43 * @param array $report Prepared report data.
|
Chris@0
|
44 * @param PHP_CodeSniffer_File $phpcsFile The file being reported on.
|
Chris@0
|
45 * @param boolean $showSources Show sources?
|
Chris@0
|
46 * @param int $width Maximum allowed line width.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @return boolean
|
Chris@0
|
49 */
|
Chris@0
|
50 public function generateFileReport(
|
Chris@0
|
51 $report,
|
Chris@0
|
52 PHP_CodeSniffer_File $phpcsFile,
|
Chris@0
|
53 $showSources=false,
|
Chris@0
|
54 $width=80
|
Chris@0
|
55 ) {
|
Chris@0
|
56 $out = new XMLWriter;
|
Chris@0
|
57 $out->openMemory();
|
Chris@0
|
58 $out->setIndent(true);
|
Chris@0
|
59
|
Chris@0
|
60 if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
Chris@0
|
61 // Nothing to print.
|
Chris@0
|
62 return false;
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 $out->startElement('file');
|
Chris@0
|
66 $out->writeAttribute('name', $report['filename']);
|
Chris@0
|
67
|
Chris@0
|
68 foreach ($report['messages'] as $line => $lineErrors) {
|
Chris@0
|
69 foreach ($lineErrors as $column => $colErrors) {
|
Chris@0
|
70 foreach ($colErrors as $error) {
|
Chris@0
|
71 $error['type'] = strtolower($error['type']);
|
Chris@0
|
72 if (PHP_CODESNIFFER_ENCODING !== 'utf-8') {
|
Chris@0
|
73 $error['message'] = iconv(PHP_CODESNIFFER_ENCODING, 'utf-8', $error['message']);
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 $out->startElement('error');
|
Chris@0
|
77 $out->writeAttribute('line', $line);
|
Chris@0
|
78 $out->writeAttribute('column', $column);
|
Chris@0
|
79 $out->writeAttribute('severity', $error['type']);
|
Chris@0
|
80 $out->writeAttribute('message', $error['message']);
|
Chris@0
|
81 $out->writeAttribute('source', $error['source']);
|
Chris@0
|
82 $out->endElement();
|
Chris@0
|
83 }
|
Chris@0
|
84 }
|
Chris@0
|
85 }//end foreach
|
Chris@0
|
86
|
Chris@0
|
87 $out->endElement();
|
Chris@0
|
88 echo $out->flush();
|
Chris@0
|
89
|
Chris@0
|
90 return true;
|
Chris@0
|
91
|
Chris@0
|
92 }//end generateFileReport()
|
Chris@0
|
93
|
Chris@0
|
94
|
Chris@0
|
95 /**
|
Chris@0
|
96 * Prints all violations for processed files, in a Checkstyle format.
|
Chris@0
|
97 *
|
Chris@0
|
98 * @param string $cachedData Any partial report data that was returned from
|
Chris@0
|
99 * generateFileReport during the run.
|
Chris@0
|
100 * @param int $totalFiles Total number of files processed during the run.
|
Chris@0
|
101 * @param int $totalErrors Total number of errors found during the run.
|
Chris@0
|
102 * @param int $totalWarnings Total number of warnings found during the run.
|
Chris@0
|
103 * @param int $totalFixable Total number of problems that can be fixed.
|
Chris@0
|
104 * @param boolean $showSources Show sources?
|
Chris@0
|
105 * @param int $width Maximum allowed line width.
|
Chris@0
|
106 * @param boolean $toScreen Is the report being printed to screen?
|
Chris@0
|
107 *
|
Chris@0
|
108 * @return void
|
Chris@0
|
109 */
|
Chris@0
|
110 public function generate(
|
Chris@0
|
111 $cachedData,
|
Chris@0
|
112 $totalFiles,
|
Chris@0
|
113 $totalErrors,
|
Chris@0
|
114 $totalWarnings,
|
Chris@0
|
115 $totalFixable,
|
Chris@0
|
116 $showSources=false,
|
Chris@0
|
117 $width=80,
|
Chris@0
|
118 $toScreen=true
|
Chris@0
|
119 ) {
|
Chris@0
|
120 echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
|
Chris@0
|
121 echo '<checkstyle version="'.PHP_CodeSniffer::VERSION.'">'.PHP_EOL;
|
Chris@0
|
122 echo $cachedData;
|
Chris@0
|
123 echo '</checkstyle>'.PHP_EOL;
|
Chris@0
|
124
|
Chris@0
|
125 }//end generate()
|
Chris@0
|
126
|
Chris@0
|
127
|
Chris@0
|
128 }//end class
|