forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'json-support' of https://github.com/jeffslofish/PHP_Cod…
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
?> |