Skip to content

Commit

Permalink
Merge branch 'json-support' of https://github.com/jeffslofish/PHP_Cod…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jun 5, 2013
2 parents ce305d1 + 9eb8672 commit b19e040
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions CodeSniffer/Reports/Json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Json report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <[email protected]>
* @author Greg Sherwood <[email protected]>
* @author Jeffrey Fisher <[email protected]>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

/**
* Json report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <[email protected]>
* @author Greg Sherwood <[email protected]>
* @author Jeffrey Fisher <[email protected]>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Json implements PHP_CodeSniffer_Report
{


/**
* Generates a json report.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$reportArr = array();
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$filename = str_replace('"', '\"', $filename);
$message = str_replace('"', '\"', $error['message']);
$type = strtolower($error['type']);
$source = $error['source'];
$severity = $error['severity'];

$reportItem = array("line" => $line,
"column" => $column,
"filename" => $filename,
"message" => $message,
"type" => $type,
"source" => $source,
"severity" => $severity);
$reportArr[] = $reportItem;
$errorsShown++;
}
}
}//end foreach
}//end foreach


echo json_encode(array("reportList" => $reportArr));
return $errorsShown;

}//end generate()


}//end class

?>

0 comments on commit b19e040

Please sign in to comment.