annotate vendor/squizlabs/php_codesniffer/src/Reports/Checkstyle.php @ 19:fa3358dc1485 tip

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