Chris@17: Chris@17: * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) Chris@17: * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence Chris@17: */ Chris@17: Chris@17: namespace PHP_CodeSniffer\Reports; Chris@17: Chris@17: use PHP_CodeSniffer\Files\File; Chris@17: Chris@17: class Csv implements Report Chris@17: { Chris@17: Chris@17: Chris@17: /** Chris@17: * Generate a partial report for a single processed file. Chris@17: * Chris@17: * Function should return TRUE if it printed or stored data about the file Chris@17: * and FALSE if it ignored the file. Returning TRUE indicates that the file and Chris@17: * its data should be counted in the grand totals. Chris@17: * Chris@17: * @param array $report Prepared report data. Chris@17: * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on. Chris@17: * @param bool $showSources Show sources? Chris@17: * @param int $width Maximum allowed line width. Chris@17: * Chris@17: * @return bool Chris@17: */ Chris@17: public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) Chris@17: { Chris@17: if ($report['errors'] === 0 && $report['warnings'] === 0) { Chris@17: // Nothing to print. Chris@17: return false; Chris@17: } Chris@17: Chris@17: foreach ($report['messages'] as $line => $lineErrors) { Chris@17: foreach ($lineErrors as $column => $colErrors) { Chris@17: foreach ($colErrors as $error) { Chris@17: $filename = str_replace('"', '\"', $report['filename']); Chris@17: $message = str_replace('"', '\"', $error['message']); Chris@17: $type = strtolower($error['type']); Chris@17: $source = $error['source']; Chris@17: $severity = $error['severity']; Chris@17: $fixable = (int) $error['fixable']; Chris@17: echo "\"$filename\",$line,$column,$type,\"$message\",$source,$severity,$fixable".PHP_EOL; Chris@17: } Chris@17: } Chris@17: } Chris@17: Chris@17: return true; Chris@17: Chris@17: }//end generateFileReport() Chris@17: Chris@17: Chris@17: /** Chris@17: * Generates a csv report. Chris@17: * Chris@17: * @param string $cachedData Any partial report data that was returned from Chris@17: * generateFileReport during the run. Chris@17: * @param int $totalFiles Total number of files processed during the run. Chris@17: * @param int $totalErrors Total number of errors found during the run. Chris@17: * @param int $totalWarnings Total number of warnings found during the run. Chris@17: * @param int $totalFixable Total number of problems that can be fixed. Chris@17: * @param bool $showSources Show sources? Chris@17: * @param int $width Maximum allowed line width. Chris@17: * @param bool $interactive Are we running in interactive mode? Chris@17: * @param bool $toScreen Is the report being printed to screen? Chris@17: * Chris@17: * @return void Chris@17: */ Chris@17: public function generate( Chris@17: $cachedData, Chris@17: $totalFiles, Chris@17: $totalErrors, Chris@17: $totalWarnings, Chris@17: $totalFixable, Chris@17: $showSources=false, Chris@17: $width=80, Chris@17: $interactive=false, Chris@17: $toScreen=true Chris@17: ) { Chris@17: echo 'File,Line,Column,Type,Message,Source,Severity,Fixable'.PHP_EOL; Chris@17: echo $cachedData; Chris@17: Chris@17: }//end generate() Chris@17: Chris@17: Chris@17: }//end class