Skip to content

Commit 06bdb0e

Browse files
committed
Add suppoert for parsing json
1 parent aa09a84 commit 06bdb0e

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $json = $converter->convert($csvIssuesString, 'csv', 'json');
2525
|------|------------|------------|
2626
| csv | YES | NO |
2727
| xml | NO | YES |
28-
| json | NO | YES |
28+
| json | YES | YES |
2929

3030
## Contributing
3131

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
],
1313
"minimum-stability": "stable",
1414
"require": {
15-
"php": ">=5.6"
15+
"php": ">=5.6",
16+
"ext-json": "*"
1617
},
1718
"autoload": {
1819
"psr-4": {

src/CodeIssue.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public function getFile()
5959
return $this->file;
6060
}
6161

62+
/**
63+
* @param $filePath
64+
*/
65+
public function changeFilePath($filePath)
66+
{
67+
$this->file = $filePath;
68+
}
69+
6270
/**
6371
* @return int
6472
*/

src/Phpcs/ReportType/JsonReport.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PlotBox\PhpcsParse\Phpcs\ReportType;
44

5+
use PlotBox\PhpcsParse\CodeIssue;
6+
57
class JsonReport implements Report
68
{
79
/** @var ReportAggregator */
@@ -58,6 +60,24 @@ public function toString(array $issues)
5860
*/
5961
public function fromString($content)
6062
{
61-
throw new NotSupportedException();
63+
$jsonData = json_decode($content);
64+
65+
$parsedResults = [];
66+
foreach($jsonData->files as $fileName => $details){
67+
foreach($details->messages as $issue){
68+
$parsedResults[] = new CodeIssue(
69+
$fileName,
70+
$issue->line,
71+
$issue->column,
72+
$issue->source,
73+
$issue->message,
74+
$issue->type,
75+
$issue->severity,
76+
$issue->fixable
77+
);
78+
}
79+
}
80+
81+
return $parsedResults;
6282
}
63-
}
83+
}

0 commit comments

Comments
 (0)