diff --git a/package.xml b/package.xml index a9293e0887..46175e2869 100644 --- a/package.xml +++ b/package.xml @@ -172,6 +172,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/src/Reports/GitHubActionsAnnotations.php b/src/Reports/GitHubActionsAnnotations.php new file mode 100644 index 0000000000..95488561f7 --- /dev/null +++ b/src/Reports/GitHubActionsAnnotations.php @@ -0,0 +1,94 @@ + + * @author Greg Sherwood + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Reports; + +use PHP_CodeSniffer\Files\File; + +class GitHubActionsAnnotations implements Report +{ + + + /** + * Generate a partial report for a single processed file. + * + * Function should return TRUE if it printed or stored data about the file + * and FALSE if it ignored the file. Returning TRUE indicates that the file and + * its data should be counted in the grand totals. + * + * @param array $report Prepared report data. + * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on. + * @param bool $showSources Show sources? + * @param int $width Maximum allowed line width. + * + * @return bool + */ + public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) + { + if ($report['errors'] === 0 && $report['warnings'] === 0) { + // Nothing to print. + return false; + } + + foreach ($report['messages'] as $line => $lineErrors) { + foreach ($lineErrors as $column => $colErrors) { + foreach ($colErrors as $error) { + $type = strtolower($error['type']); + + $filename = $report['filename']; + + $log = $error['message'].'%0A%0A'.$error['source']; + + echo "::{$type} file={$filename},line={$line},col=$column::{$log}".PHP_EOL; + } + } + }//end foreach + + return true; + + }//end generateFileReport() + + + /** + * Generates a report with lines parsable by GitHub Actions. + * + * @param string $cachedData Any partial report data that was returned from + * generateFileReport during the run. + * @param int $totalFiles Total number of files processed during the run. + * @param int $totalErrors Total number of errors found during the run. + * @param int $totalWarnings Total number of warnings found during the run. + * @param int $totalFixable Total number of problems that can be fixed. + * @param bool $showSources Show sources? + * @param int $width Maximum allowed line width. + * @param bool $interactive Are we running in interactive mode? + * @param bool $toScreen Is the report being printed to screen? + * + * @return void + */ + public function generate( + $cachedData, + $totalFiles, + $totalErrors, + $totalWarnings, + $totalFixable, + $showSources=false, + $width=80, + $interactive=false, + $toScreen=true + ) { + echo $cachedData; + + }//end generate() + + +}//end class