Mercurial > hg > cmmr2012-drupal-site
comparison vendor/squizlabs/php_codesniffer/src/Reports/Junit.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 * JUnit report for PHP_CodeSniffer. | |
4 * | |
5 * @author Oleg Lobach <oleg@lobach.info> | |
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\Config; | |
14 use PHP_CodeSniffer\Files\File; | |
15 | |
16 class Junit implements Report | |
17 { | |
18 | |
19 | |
20 /** | |
21 * Generate a partial report for a single processed file. | |
22 * | |
23 * Function should return TRUE if it printed or stored data about the file | |
24 * and FALSE if it ignored the file. Returning TRUE indicates that the file and | |
25 * its data should be counted in the grand totals. | |
26 * | |
27 * @param array $report Prepared report data. | |
28 * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on. | |
29 * @param bool $showSources Show sources? | |
30 * @param int $width Maximum allowed line width. | |
31 * | |
32 * @return bool | |
33 */ | |
34 public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) | |
35 { | |
36 $out = new \XMLWriter; | |
37 $out->openMemory(); | |
38 $out->setIndent(true); | |
39 | |
40 $out->startElement('testsuite'); | |
41 $out->writeAttribute('name', $report['filename']); | |
42 $out->writeAttribute('errors', 0); | |
43 | |
44 if (count($report['messages']) === 0) { | |
45 $out->writeAttribute('tests', 1); | |
46 $out->writeAttribute('failures', 0); | |
47 | |
48 $out->startElement('testcase'); | |
49 $out->writeAttribute('name', $report['filename']); | |
50 $out->endElement(); | |
51 } else { | |
52 $failures = ($report['errors'] + $report['warnings']); | |
53 $out->writeAttribute('tests', $failures); | |
54 $out->writeAttribute('failures', $failures); | |
55 | |
56 foreach ($report['messages'] as $line => $lineErrors) { | |
57 foreach ($lineErrors as $column => $colErrors) { | |
58 foreach ($colErrors as $error) { | |
59 $out->startElement('testcase'); | |
60 $out->writeAttribute('name', $error['source'].' at '.$report['filename']." ($line:$column)"); | |
61 | |
62 $error['type'] = strtolower($error['type']); | |
63 if ($phpcsFile->config->encoding !== 'utf-8') { | |
64 $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']); | |
65 } | |
66 | |
67 $out->startElement('failure'); | |
68 $out->writeAttribute('type', $error['type']); | |
69 $out->writeAttribute('message', $error['message']); | |
70 $out->endElement(); | |
71 | |
72 $out->endElement(); | |
73 } | |
74 } | |
75 } | |
76 }//end if | |
77 | |
78 $out->endElement(); | |
79 echo $out->flush(); | |
80 return true; | |
81 | |
82 }//end generateFileReport() | |
83 | |
84 | |
85 /** | |
86 * Prints all violations for processed files, in a proprietary XML format. | |
87 * | |
88 * @param string $cachedData Any partial report data that was returned from | |
89 * generateFileReport during the run. | |
90 * @param int $totalFiles Total number of files processed during the run. | |
91 * @param int $totalErrors Total number of errors found during the run. | |
92 * @param int $totalWarnings Total number of warnings found during the run. | |
93 * @param int $totalFixable Total number of problems that can be fixed. | |
94 * @param bool $showSources Show sources? | |
95 * @param int $width Maximum allowed line width. | |
96 * @param bool $interactive Are we running in interactive mode? | |
97 * @param bool $toScreen Is the report being printed to screen? | |
98 * | |
99 * @return void | |
100 */ | |
101 public function generate( | |
102 $cachedData, | |
103 $totalFiles, | |
104 $totalErrors, | |
105 $totalWarnings, | |
106 $totalFixable, | |
107 $showSources=false, | |
108 $width=80, | |
109 $interactive=false, | |
110 $toScreen=true | |
111 ) { | |
112 // Figure out the total number of tests. | |
113 $tests = 0; | |
114 $matches = []; | |
115 preg_match_all('/tests="([0-9]+)"/', $cachedData, $matches); | |
116 if (isset($matches[1]) === true) { | |
117 foreach ($matches[1] as $match) { | |
118 $tests += $match; | |
119 } | |
120 } | |
121 | |
122 $failures = ($totalErrors + $totalWarnings); | |
123 echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; | |
124 echo '<testsuites name="PHP_CodeSniffer '.Config::VERSION.'" errors="0" tests="'.$tests.'" failures="'.$failures.'">'.PHP_EOL; | |
125 echo $cachedData; | |
126 echo '</testsuites>'.PHP_EOL; | |
127 | |
128 }//end generate() | |
129 | |
130 | |
131 }//end class |