Skip to content
This repository was archived by the owner on Dec 8, 2017. It is now read-only.

Commit 493c341

Browse files
author
Samuel Parkinson
committed
Use json output with codesniffer.
1 parent 29863be commit 493c341

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/Review/PHP/PhpCodeSnifferReview.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function canReview(FileInterface $file)
8888
*/
8989
public function review(ReporterInterface $reporter, FileInterface $file)
9090
{
91-
$cmd = 'vendor/bin/phpcs --report=csv ';
91+
$cmd = 'vendor/bin/phpcs --report=json ';
9292

9393
if ($this->getOptionsForConsole()) {
9494
$cmd .= $this->getOptionsForConsole();
@@ -99,19 +99,21 @@ public function review(ReporterInterface $reporter, FileInterface $file)
9999
$process = $this->getProcess($cmd);
100100
$process->run();
101101

102-
// Create the array of outputs and remove empty values.
103-
$output = array_filter(explode(PHP_EOL, $process->getOutput()));
104-
105102
if (! $process->isSuccessful()) {
106103

107-
array_shift($output);
104+
// Create the array of outputs and remove empty values.
105+
$output = json_decode($process->getOutput(), true);
106+
107+
$filter = function ($acc, $file) {
108+
if ($file['errors'] > 0 || $file['warnings'] > 0) {
109+
return $acc + $file['messages'];
110+
}
111+
};
108112

109-
foreach ($output as $error) {
110-
$split = explode(',', $error);
111-
$message = str_replace('"', '', $split[4]) . ' on line ' . $split[1];
113+
foreach (array_reduce($output['files'], $filter, []) as $error) {
114+
$message = $error['message'] . ' on line ' . $error['line'];
112115
$reporter->warning($message, $this, $file);
113116
}
114-
115117
}
116118
}
117119
}

0 commit comments

Comments
 (0)