@@ -29,7 +29,6 @@ const OUTPUT_UNDERLINED = "\033[4m";
2929const OUTPUT_UNUNDERLINED = "\033[24m " ;
3030
3131$ logo = file_get_contents ( PHPCS_DIFF_PLUGIN_DIR . '/logo ' );
32- echo "\n$ logo \n" . OUTPUT_UNDERLINED . COLOUR_SECONDARY . 'https://github.com/zaantar/phpcs-diff ' . OUTPUT_RESET . "\n\n" ;
3332
3433require_once PHPCS_DIFF_PLUGIN_DIR . '/vendor/autoload.php ' ;
3534
@@ -48,6 +47,7 @@ $getopt = new GetOpt(
4847 [ 'excluded_exts ' , GetOpt::OPTIONAL_ARGUMENT ],
4948 [ 'standards_location ' , GetOpt::OPTIONAL_ARGUMENT ],
5049 [ 'default_standards_location ' , GetOpt::NO_ARGUMENT ],
50+ [ 'format ' , GetOpt::OPTIONAL_ARGUMENT ],
5151 ]
5252);
5353
@@ -83,6 +83,8 @@ $no_colours = $getopt->offsetExists( 'no_colours' );
8383$ excluded_exts = $ getopt ->getOption ( 'excluded_exts ' );
8484$ standards_location = $ getopt ->getOption ( 'standards_location ' );
8585$ default_standards_location = $ getopt ->getOption ( 'default_standards_location ' );
86+ $ format = $ getopt ->getOption ( 'format ' );
87+ $ do_echo = $ format !== 'json ' ;
8688
8789$ sniff_unstaged = $ getopt ->offsetExists ( 'sniff_unstaged ' );
8890if ( $ sniff_unstaged ) {
@@ -137,11 +139,15 @@ if( $default_standards_location ) {
137139}
138140
139141$ logger = new Log \ShellLogger ( (int ) $ log_level );
140- $ options = [ 'ignore-space-change ' => $ ignore_space_changes , 'standards_location ' => $ standards_location ];
142+ $ options = [ 'ignore-space-change ' => $ ignore_space_changes , 'standards_location ' => $ standards_location, ' format ' => $ format ];
141143$ version_control = new Backends \Git ( '' , $ logger , $ options );
142144$ controller = new Main ( $ version_control , $ logger , $ options );
143145$ controller ->set_phpcs_standard ( $ phpcs_standard );
144146
147+ if ( $ do_echo ) {
148+ echo "\n$ logo \n" . OUTPUT_UNDERLINED . COLOUR_SECONDARY . 'https://github.com/zaantar/phpcs-diff ' . OUTPUT_RESET . "\n\n" ;
149+ }
150+
145151try {
146152 $ found_issues = $ controller ->run ( $ start_revision , $ end_revision , '' , $ excluded_exts );
147153} catch ( \Exception $ e ) {
@@ -201,6 +207,15 @@ function echo_chapter( $title, $items ) {
201207 echo PHP_EOL ;
202208}
203209
210+ if ( $ format === 'json ' ) {
211+ echo json_encode ( array (
212+ 'blockers ' => $ blockers ,
213+ 'warnings ' => $ warnings ,
214+ 'notes ' => $ notes ,
215+ ) );
216+ exit ();
217+ }
218+
204219echo PHP_EOL ;
205220echo_chapter ( 'Blockers ' , $ blockers );
206221echo_chapter ( 'Warnings ' , $ warnings );
0 commit comments