@@ -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