Mercurial > hg > isophonics-drupal-site
comparison vendor/squizlabs/php_codesniffer/src/Reports/Xml.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | |
2 /** | |
3 * XML 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\Config; | |
13 use PHP_CodeSniffer\Files\File; | |
14 | |
15 class Xml 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 $out = new \XMLWriter; | |
36 $out->openMemory(); | |
37 $out->setIndent(true); | |
38 $out->setIndentString(' '); | |
39 $out->startDocument('1.0', 'UTF-8'); | |
40 | |
41 if ($report['errors'] === 0 && $report['warnings'] === 0) { | |
42 // Nothing to print. | |
43 return false; | |
44 } | |
45 | |
46 $out->startElement('file'); | |
47 $out->writeAttribute('name', $report['filename']); | |
48 $out->writeAttribute('errors', $report['errors']); | |
49 $out->writeAttribute('warnings', $report['warnings']); | |
50 $out->writeAttribute('fixable', $report['fixable']); | |
51 | |
52 foreach ($report['messages'] as $line => $lineErrors) { | |
53 foreach ($lineErrors as $column => $colErrors) { | |
54 foreach ($colErrors as $error) { | |
55 $error['type'] = strtolower($error['type']); | |
56 if ($phpcsFile->config->encoding !== 'utf-8') { | |
57 $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']); | |
58 } | |
59 | |
60 $out->startElement($error['type']); | |
61 $out->writeAttribute('line', $line); | |
62 $out->writeAttribute('column', $column); | |
63 $out->writeAttribute('source', $error['source']); | |
64 $out->writeAttribute('severity', $error['severity']); | |
65 $out->writeAttribute('fixable', (int) $error['fixable']); | |
66 $out->text($error['message']); | |
67 $out->endElement(); | |
68 } | |
69 } | |
70 }//end foreach | |
71 | |
72 $out->endElement(); | |
73 | |
74 // Remove the start of the document because we will | |
75 // add that manually later. We only have it in here to | |
76 // properly set the encoding. | |
77 $content = $out->flush(); | |
78 $content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL))); | |
79 echo $content; | |
80 | |
81 return true; | |
82 | |
83 }//end generateFileReport() | |
84 | |
85 | |
86 /** | |
87 * Prints all violations for processed files, in a proprietary XML format. | |
88 * | |
89 * @param string $cachedData Any partial report data that was returned from | |
90 * generateFileReport during the run. | |
91 * @param int $totalFiles Total number of files processed during the run. | |
92 * @param int $totalErrors Total number of errors found during the run. | |
93 * @param int $totalWarnings Total number of warnings found during the run. | |
94 * @param int $totalFixable Total number of problems that can be fixed. | |
95 * @param bool $showSources Show sources? | |
96 * @param int $width Maximum allowed line width. | |
97 * @param bool $interactive Are we running in interactive mode? | |
98 * @param bool $toScreen Is the report being printed to screen? | |
99 * | |
100 * @return void | |
101 */ | |
102 public function generate( | |
103 $cachedData, | |
104 $totalFiles, | |
105 $totalErrors, | |
106 $totalWarnings, | |
107 $totalFixable, | |
108 $showSources=false, | |
109 $width=80, | |
110 $interactive=false, | |
111 $toScreen=true | |
112 ) { | |
113 echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; | |
114 echo '<phpcs version="'.Config::VERSION.'">'.PHP_EOL; | |
115 echo $cachedData; | |
116 echo '</phpcs>'.PHP_EOL; | |
117 | |
118 }//end generate() | |
119 | |
120 | |
121 }//end class |