annotate vendor/squizlabs/php_codesniffer/src/Reports/Checkstyle.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
rev   line source
Chris@4 1 <?php
Chris@4 2 /**
Chris@4 3 * Checkstyle report for PHP_CodeSniffer.
Chris@4 4 *
Chris@4 5 * @author Greg Sherwood <gsherwood@squiz.net>
Chris@4 6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Chris@4 7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
Chris@4 8 */
Chris@4 9
Chris@4 10 namespace PHP_CodeSniffer\Reports;
Chris@4 11
Chris@4 12 use PHP_CodeSniffer\Config;
Chris@4 13 use PHP_CodeSniffer\Files\File;
Chris@4 14
Chris@4 15 class Checkstyle implements Report
Chris@4 16 {
Chris@4 17
Chris@4 18
Chris@4 19 /**
Chris@4 20 * Generate a partial report for a single processed file.
Chris@4 21 *
Chris@4 22 * Function should return TRUE if it printed or stored data about the file
Chris@4 23 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
Chris@4 24 * its data should be counted in the grand totals.
Chris@4 25 *
Chris@4 26 * @param array $report Prepared report data.
Chris@4 27 * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
Chris@4 28 * @param bool $showSources Show sources?
Chris@4 29 * @param int $width Maximum allowed line width.
Chris@4 30 *
Chris@4 31 * @return bool
Chris@4 32 */
Chris@4 33 public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
Chris@4 34 {
Chris@4 35 $out = new \XMLWriter;
Chris@4 36 $out->openMemory();
Chris@4 37 $out->setIndent(true);
Chris@4 38
Chris@4 39 if ($report['errors'] === 0 && $report['warnings'] === 0) {
Chris@4 40 // Nothing to print.
Chris@4 41 return false;
Chris@4 42 }
Chris@4 43
Chris@4 44 $out->startElement('file');
Chris@4 45 $out->writeAttribute('name', $report['filename']);
Chris@4 46
Chris@4 47 foreach ($report['messages'] as $line => $lineErrors) {
Chris@4 48 foreach ($lineErrors as $column => $colErrors) {
Chris@4 49 foreach ($colErrors as $error) {
Chris@4 50 $error['type'] = strtolower($error['type']);
Chris@4 51 if ($phpcsFile->config->encoding !== 'utf-8') {
Chris@4 52 $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
Chris@4 53 }
Chris@4 54
Chris@4 55 $out->startElement('error');
Chris@4 56 $out->writeAttribute('line', $line);
Chris@4 57 $out->writeAttribute('column', $column);
Chris@4 58 $out->writeAttribute('severity', $error['type']);
Chris@4 59 $out->writeAttribute('message', $error['message']);
Chris@4 60 $out->writeAttribute('source', $error['source']);
Chris@4 61 $out->endElement();
Chris@4 62 }
Chris@4 63 }
Chris@4 64 }//end foreach
Chris@4 65
Chris@4 66 $out->endElement();
Chris@4 67 echo $out->flush();
Chris@4 68
Chris@4 69 return true;
Chris@4 70
Chris@4 71 }//end generateFileReport()
Chris@4 72
Chris@4 73
Chris@4 74 /**
Chris@4 75 * Prints all violations for processed files, in a Checkstyle format.
Chris@4 76 *
Chris@4 77 * @param string $cachedData Any partial report data that was returned from
Chris@4 78 * generateFileReport during the run.
Chris@4 79 * @param int $totalFiles Total number of files processed during the run.
Chris@4 80 * @param int $totalErrors Total number of errors found during the run.
Chris@4 81 * @param int $totalWarnings Total number of warnings found during the run.
Chris@4 82 * @param int $totalFixable Total number of problems that can be fixed.
Chris@4 83 * @param bool $showSources Show sources?
Chris@4 84 * @param int $width Maximum allowed line width.
Chris@4 85 * @param bool $interactive Are we running in interactive mode?
Chris@4 86 * @param bool $toScreen Is the report being printed to screen?
Chris@4 87 *
Chris@4 88 * @return void
Chris@4 89 */
Chris@4 90 public function generate(
Chris@4 91 $cachedData,
Chris@4 92 $totalFiles,
Chris@4 93 $totalErrors,
Chris@4 94 $totalWarnings,
Chris@4 95 $totalFixable,
Chris@4 96 $showSources=false,
Chris@4 97 $width=80,
Chris@4 98 $interactive=false,
Chris@4 99 $toScreen=true
Chris@4 100 ) {
Chris@4 101 echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
Chris@4 102 echo '<checkstyle version="'.Config::VERSION.'">'.PHP_EOL;
Chris@4 103 echo $cachedData;
Chris@4 104 echo '</checkstyle>'.PHP_EOL;
Chris@4 105
Chris@4 106 }//end generate()
Chris@4 107
Chris@4 108
Chris@4 109 }//end class