@@ -13,7 +13,7 @@ namespace PHPCSDiff;
1313
1414use PHPCSDiff \Log \LoggerInterface ;
1515
16- define ( 'PHPCS_DIFF_PLUGIN_DIR ' , str_replace ('\\' , '/ ' , dirname ( dirname ( __FILE__ ) ) ) );
16+ define ( 'PHPCS_DIFF_PLUGIN_DIR ' , str_replace ( '\\' , '/ ' , dirname ( dirname ( __FILE__ ) ) ) );
1717define ( 'PHPCS_DIFF_COMMAND ' , '" ' . PHPCS_DIFF_PLUGIN_DIR . '/vendor/bin/phpcs ' . '" ' );
1818define ( 'PHPCS_DIFF_STANDARDS ' , PHPCS_DIFF_PLUGIN_DIR . '/standards ' );
1919
@@ -36,24 +36,26 @@ $getopt = new \GetOpt\GetOpt(
3636 [
3737 [ 's ' , 'start_revision ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
3838 [ 'e ' , 'end_revision ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
39- [ 't ' , 'tolerance ' ],
40- [ 'standard ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
41- [ 'log_level ' ],
42- [ 'ignore_space_changes ' , \GetOpt \GetOpt::NO_ARGUMENT ],
43- [ 'sniff_unstaged ' , \GetOpt \GetOpt::NO_ARGUMENT ],
44- [ 'no_colours ' , \GetOpt \GetOpt::NO_ARGUMENT ],
45- [ 'colour_primary ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
46- [ 'colour_secondary ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
39+ [ 't ' , 'tolerance ' ],
40+ [ 'standard ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
41+ [ 'log_level ' ],
42+ [ 'ignore_space_changes ' , \GetOpt \GetOpt::NO_ARGUMENT ],
43+ [ 'sniff_unstaged ' , \GetOpt \GetOpt::NO_ARGUMENT ],
44+ [ 'no_colours ' , \GetOpt \GetOpt::NO_ARGUMENT ],
45+ [ 'colour_primary ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
46+ [ 'colour_secondary ' , \GetOpt \GetOpt::REQUIRED_ARGUMENT ],
4747 [ 'excluded_exts ' , \GetOpt \GetOpt::OPTIONAL_ARGUMENT ],
4848 ]
4949);
5050
5151$ getopt ->getOption ( 'tolerance ' , true )
52- ->setMode ( \GetOpt \GetOpt::OPTIONAL_ARGUMENT )
53- ->setValidation ( function ( $ value ) {
54- return in_array ( $ value , [ 'blockers ' , 'warnings ' , 'notes ' , 'none ' ] );
55- } )
56- ->setDefaultValue ( 'notes ' );
52+ ->setMode ( \GetOpt \GetOpt::OPTIONAL_ARGUMENT )
53+ ->setValidation (
54+ function ( $ value ) {
55+ return in_array ( $ value , [ 'blockers ' , 'warnings ' , 'notes ' , 'none ' ] );
56+ }
57+ )
58+ ->setDefaultValue ( 'notes ' );
5759
5860$ getopt ->getOption ( 'log_level ' , true )
5961 ->setMode ( \GetOpt \GetOpt::OPTIONAL_ARGUMENT )
6567} catch ( \GetOpt \ArgumentException $ exception ) {
6668 file_put_contents ( 'php://stderr ' , $ exception ->getMessage () . PHP_EOL );
6769 echo PHP_EOL . $ getopt ->getHelpText ();
70+
6871 return 1 ;
6972}
7073
@@ -77,48 +80,48 @@ $no_colours = $getopt->offsetExists( 'no_colours' );
7780$ excluded_exts = $ getopt ->getOption ( 'excluded_exts ' );
7881
7982$ sniff_unstaged = $ getopt ->offsetExists ( 'sniff_unstaged ' );
80- if ( $ sniff_unstaged ) {
81- $ start_revision = 'HEAD ' ;
82- $ end_revision = Backends \Git::UNSTAGED ;
83- } elseif ( null == $ end_revision ) {
84- $ end_revision = Backends \Git::UNSTAGED ;
83+ if ( $ sniff_unstaged ) {
84+ $ start_revision = 'HEAD ' ;
85+ $ end_revision = Backends \Git::UNSTAGED ;
86+ } elseif ( null == $ end_revision ) {
87+ $ end_revision = Backends \Git::UNSTAGED ;
8588}
8689
8790global $ colour_primary , $ colour_secondary ;
8891
89- if ( $ no_colours ) {
92+ if ( $ no_colours ) {
9093 $ colour_primary = '' ;
9194 $ colour_secondary = '' ;
9295} else {
93- function arg_to_colour ( $ arg , $ default ) {
94- $ arg_to_colour_map = [
95- 'default ' => "\e[39m " ,
96- 'black ' => "\e[30m " ,
97- 'red ' => "\e[31m " ,
98- 'green ' => "\e[32m " ,
99- 'yellow ' => "\e[33m " ,
100- 'blue ' => "\e[34m " ,
101- 'magenta ' => "\e[35m " ,
102- 'cyan ' => "\e[36m " ,
103- 'lightgray ' => "\e[37m " ,
104- 'darkgray ' => "\e[90m " ,
105- 'lightred ' => "\e[91m " ,
106- 'lightgreen ' => "\e[92m " ,
107- 'lightyellow ' => "\e[93m " ,
108- 'lightblue ' => "\e[94m " ,
109- 'lightmagenta ' => "\e[95m " ,
110- 'lightcyan ' => "\e[96m " ,
111- 'white ' => "\e[97m "
112- ];
113-
114- if ( ! array_key_exists ( $ arg , $ arg_to_colour_map ) ) {
115- return $ default ;
116- }
117-
118- return $ arg_to_colour_map [ $ arg ];
119- }
120-
121- $ colour_primary = $ getopt ->offsetExists ( 'colour_primary ' ) ? arg_to_colour ( $ getopt ->getOption ( 'colour_primary ' ), COLOUR_PRIMARY ) : COLOUR_PRIMARY ;
96+ function arg_to_colour ( $ arg , $ default ) {
97+ $ arg_to_colour_map = [
98+ 'default ' => "\e[39m " ,
99+ 'black ' => "\e[30m " ,
100+ 'red ' => "\e[31m " ,
101+ 'green ' => "\e[32m " ,
102+ 'yellow ' => "\e[33m " ,
103+ 'blue ' => "\e[34m " ,
104+ 'magenta ' => "\e[35m " ,
105+ 'cyan ' => "\e[36m " ,
106+ 'lightgray ' => "\e[37m " ,
107+ 'darkgray ' => "\e[90m " ,
108+ 'lightred ' => "\e[91m " ,
109+ 'lightgreen ' => "\e[92m " ,
110+ 'lightyellow ' => "\e[93m " ,
111+ 'lightblue ' => "\e[94m " ,
112+ 'lightmagenta ' => "\e[95m " ,
113+ 'lightcyan ' => "\e[96m " ,
114+ 'white ' => "\e[97m " ,
115+ ];
116+
117+ if ( ! array_key_exists ( $ arg , $ arg_to_colour_map ) ) {
118+ return $ default ;
119+ }
120+
121+ return $ arg_to_colour_map [ $ arg ];
122+ }
123+
124+ $ colour_primary = $ getopt ->offsetExists ( 'colour_primary ' ) ? arg_to_colour ( $ getopt ->getOption ( 'colour_primary ' ), COLOUR_PRIMARY ) : COLOUR_PRIMARY ;
122125 $ colour_secondary = $ getopt ->offsetExists ( 'colour_secondary ' ) ? arg_to_colour ( $ getopt ->getOption ( 'colour_secondary ' ), COLOUR_SECONDARY ) : COLOUR_SECONDARY ;
123126}
124127
@@ -138,30 +141,31 @@ try {
138141 . 'Trace: ' . $ e ->getTraceAsString ()
139142 );
140143
141- exit (1 );
144+ exit ( 1 );
142145}
143146
144147
145148function render_line ( $ filename , $ line , $ column , $ message , $ source , $ issue_number ) {
146149 global $ colour_primary , $ colour_secondary ;
147- return OUTPUT_BOLD . $ colour_primary . "* "
148- . $ colour_secondary . OUTPUT_REVERSE . $ issue_number . OUTPUT_UNREVERSE . " "
149- . $ colour_primary . $ filename . ": " . $ line . ': ' . $ column . OUTPUT_UNBOLD . PHP_EOL
150- . "\t" . $ source . ": " . PHP_EOL
151- . "\t" . $ colour_secondary . $ message . OUTPUT_RESET ;
150+
151+ return OUTPUT_BOLD . $ colour_primary . "* "
152+ . $ colour_secondary . OUTPUT_REVERSE . $ issue_number . OUTPUT_UNREVERSE . " "
153+ . $ colour_primary . $ filename . ": " . $ line . ': ' . $ column . OUTPUT_UNBOLD . PHP_EOL
154+ . "\t" . $ source . ": " . PHP_EOL
155+ . "\t" . $ colour_secondary . $ message . OUTPUT_RESET ;
152156}
153157
154158$ blockers = $ warnings = $ notes = [];
155159foreach ( $ found_issues as $ filename => $ issues ) {
156160 foreach ( $ issues as $ line => $ line_issues ) {
157- foreach ( $ line_issues as $ issue ) {
158- $ line_args = [ $ filename , $ line , $ issue ['column ' ], $ issue ['message ' ], $ issue ['source ' ] ];
161+ foreach ( $ line_issues as $ issue ) {
162+ $ line_args = [ $ filename , $ line , $ issue ['column ' ], $ issue ['message ' ], $ issue ['source ' ] ];
159163
160164 if ( 'ERROR ' === $ issue ['level ' ] ) {
161165 $ blockers [] = $ line_args ;
162- } else if ( 'WARNING ' === $ issue ['level ' ] ) {
166+ } elseif ( 'WARNING ' === $ issue ['level ' ] ) {
163167 $ warnings [] = $ line_args ;
164- } else if ( 'NOTE ' === $ issue ['level ' ] ) {
168+ } elseif ( 'NOTE ' === $ issue ['level ' ] ) {
165169 $ notes [] = $ line_args ;
166170 }
167171 }
@@ -171,15 +175,15 @@ foreach ( $found_issues as $filename => $issues ) {
171175function echo_chapter ( $ title , $ items ) {
172176 global $ colour_primary ;
173177
174- if ( empty ( $ items ) ) {
175- return ;
176- }
178+ if ( empty ( $ items ) ) {
179+ return ;
180+ }
177181
178182 echo OUTPUT_REVERSE . OUTPUT_BOLD . $ colour_primary . "### " . $ title . OUTPUT_RESET . PHP_EOL . PHP_EOL ;
179183
180184 $ issue_number = 1 ;
181185 foreach ( $ items as $ line_args ) {
182- $ line_args [] = $ issue_number ++;
186+ $ line_args [] = $ issue_number ++;
183187 echo call_user_func_array ( '\PHPCSDiff\render_line ' , $ line_args ) . PHP_EOL ;
184188 }
185189
@@ -191,21 +195,21 @@ echo_chapter( 'Blockers', $blockers );
191195echo_chapter ( 'Warnings ' , $ warnings );
192196echo_chapter ( 'Notes ' , $ notes );
193197printf (
194- "\nAnalysis completed with %s blockers, %s warnings and %s notes. \n" ,
195- count ( $ blockers ), count ( $ warnings ), count ( $ notes )
198+ "\nAnalysis completed with %s blockers, %s warnings and %s notes. \n" ,
199+ count ( $ blockers ), count ( $ warnings ), count ( $ notes )
196200);
197201
198202$ tolerance = $ getopt ->getOption ( 'tolerance ' );
199- if ( 'blockers ' === $ tolerance ) {
200- exit (0 );
201- } elseif ( empty ( $ blockers ) ) {
202- if ( 'warnings ' === $ tolerance ) {
203- exit (0 );
204- } elseif ( empty ( $ warnings ) ) {
205- if ( 'notes ' === $ tolerance || empty ( $ notes ) ) {
206- exit (0 );
207- }
208- }
203+ if ( 'blockers ' === $ tolerance ) {
204+ exit ( 0 );
205+ } elseif ( empty ( $ blockers ) ) {
206+ if ( 'warnings ' === $ tolerance ) {
207+ exit ( 0 );
208+ } elseif ( empty ( $ warnings ) ) {
209+ if ( 'notes ' === $ tolerance || empty ( $ notes ) ) {
210+ exit ( 0 );
211+ }
212+ }
209213}
210214
211- exit (1 );
215+ exit ( 1 );
0 commit comments