Skip to content

Commit b0c8211

Browse files
committed
Further improve the output of the phpcs-diff script. Also make the log messages more verbose.
1 parent ef01c57 commit b0c8211

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

bin/phpcs-diff

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ try {
140140
}
141141

142142

143-
function render_line( $filename, $line, $column, $message, $source ) {
143+
function render_line( $filename, $line, $column, $message, $source, $issue_number ) {
144144
global $colour_primary, $colour_secondary;
145-
return OUTPUT_BOLD . $colour_primary . "* " . $filename . ":" . $line . ':' . $column . OUTPUT_UNBOLD . PHP_EOL
145+
return OUTPUT_BOLD . $colour_primary . "* "
146+
. $colour_secondary . OUTPUT_REVERSE . $issue_number . OUTPUT_UNREVERSE . " "
147+
. $colour_primary . $filename . ":" . $line . ':' . $column . OUTPUT_UNBOLD . PHP_EOL
146148
. "\t" . $source . ": " . PHP_EOL
147149
. "\t" . $colour_secondary . $message . OUTPUT_RESET;
148150
}
@@ -151,14 +153,14 @@ $blockers = $warnings = $notes = [];
151153
foreach ( $found_issues as $filename => $issues ) {
152154
foreach ( $issues as $line => $line_issues ) {
153155
foreach( $line_issues as $issue ) {
154-
$output = render_line( $filename, $line, $issue['column'], $issue['message'], $issue['source'] );
156+
$line_args = [ $filename, $line, $issue['column'], $issue['message'], $issue['source'] ];
155157

156158
if ( 'ERROR' === $issue['level'] ) {
157-
$blockers[] = $output;
159+
$blockers[] = $line_args;
158160
} else if ( 'WARNING' === $issue['level'] ) {
159-
$warnings[] = $output;
161+
$warnings[] = $line_args;
160162
} else if ( 'NOTE' === $issue['level'] ) {
161-
$notes[] = $output;
163+
$notes[] = $line_args;
162164
}
163165
}
164166
}
@@ -172,8 +174,11 @@ function echo_chapter( $title, $items ) {
172174
}
173175

174176
echo OUTPUT_REVERSE . OUTPUT_BOLD . $colour_primary . "### " . $title . OUTPUT_RESET . PHP_EOL . PHP_EOL;
175-
foreach ( $items as $item ) {
176-
echo $item . PHP_EOL;
177+
178+
$issue_number = 1;
179+
foreach ( $items as $line_args ) {
180+
$line_args[] = $issue_number++;
181+
echo call_user_func_array( '\PHPCSDiff\render_line', $line_args ) . PHP_EOL;
177182
}
178183

179184
echo PHP_EOL;
@@ -201,4 +206,4 @@ if( 'blockers' === $tolerance ) {
201206
}
202207
}
203208

204-
exit(1);
209+
exit(1);

inc/Main.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,25 @@ public function run( $oldest_rev, $newest_rev, $directory = '' ) {
9595

9696
$diff_info = $this->version_control->parse_diff_for_info( $diff );
9797
$file_diffs = $diff_info['file_diffs'];
98+
$total_changed_file_count = count( $file_diffs );
99+
$this->log->log( LoggerInterface::INFO, sprintf( 'Retrieved diffs for %d changed files.', $total_changed_file_count ) );
98100

99101
$found_issues = array();
100102
$found_issues_count = 0;
103+
$current_file_number = 1;
101104
foreach( $file_diffs as $filename => $file_info ) {
105+
106+
$this->log->log( LoggerInterface::INFO, sprintf(
107+
'Processing file %d of %d: %s...',
108+
$current_file_number++,
109+
$total_changed_file_count,
110+
$filename
111+
) );
112+
102113
$line_mapping = new LineMapping();
103114
$line_mapping->count_lines( $file_info['lines'] );
104115
if ( ! $line_mapping->has_actionable_changes() ) {
116+
$this->log->log( LoggerInterface::INFO, 'No actionable changes found.' );
105117
continue;
106118
}
107119

@@ -116,6 +128,9 @@ public function run( $oldest_rev, $newest_rev, $directory = '' ) {
116128
}
117129
$found_issues[ $filename ] = $processed_file;
118130
$found_issues_count += count( $processed_file );
131+
$this->log->log( LoggerInterface::INFO, sprintf(
132+
'Found %d issues in the changed code.', count( $processed_file )
133+
) );
119134
}
120135

121136
return $found_issues;

0 commit comments

Comments
 (0)