Skip to content

Commit

Permalink
Report Full: fix delimiter line bug
Browse files Browse the repository at this point in the history
When determining the max message length, the calculation did not take potential explicit multi-line messages into account and would base the delimiter line length on the length of the complete message, not on the length of the individual lines.

Fixed now.
  • Loading branch information
jrfnl committed Dec 11, 2023
1 parent 18cb0d4 commit dff4c58
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Reports/Full.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,28 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
foreach ($report['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$length = strlen($error['message']);
// Start with the presumption of a single line error message.
$length = strlen($error['message']);
$srcLength = (strlen($error['source']) + 3);
if ($showSources === true) {
$length += (strlen($error['source']) + 3);
$length += $srcLength;
}

// ... but also handle multi-line messages correctly.
if (strpos($error['message'], "\n") !== false) {
$errorLines = explode("\n", $error['message']);
$length = max(array_map('strlen', $errorLines));

if ($showSources === true) {
$lastLine = array_pop($errorLines);
$length = max($length, (strlen($lastLine) + $srcLength));
}
}

$maxErrorLength = max($maxErrorLength, ($length + 1));
}
}
}
}//end foreach
}//end foreach
}//end foreach

$file = $report['filename'];
$fileLength = strlen($file);
Expand Down

0 comments on commit dff4c58

Please sign in to comment.