Skip to content

Commit 1cedc70

Browse files
committed
Report Full: fix delimiter line bug
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.
1 parent 75a2783 commit 1cedc70

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Reports/Full.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,28 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
6363
foreach ($report['messages'] as $line => $lineErrors) {
6464
foreach ($lineErrors as $column => $colErrors) {
6565
foreach ($colErrors as $error) {
66-
$length = strlen($error['message']);
66+
// Start with the presumption of a single line error message.
67+
$length = strlen($error['message']);
68+
$srcLength = (strlen($error['source']) + 3);
6769
if ($showSources === true) {
68-
$length += (strlen($error['source']) + 3);
70+
$length += $srcLength;
71+
}
72+
73+
// ... but also handle multi-line messages correctly.
74+
if (strpos($error['message'], "\n") !== false) {
75+
$errorLines = explode("\n", $error['message']);
76+
$length = max(array_map('strlen', $errorLines));
77+
78+
if ($showSources === true) {
79+
$lastLine = array_pop($errorLines);
80+
$length = max($length, (strlen($lastLine) + $srcLength));
81+
}
6982
}
7083

7184
$maxErrorLength = max($maxErrorLength, ($length + 1));
72-
}
73-
}
74-
}
85+
}//end foreach
86+
}//end foreach
87+
}//end foreach
7588

7689
$file = $report['filename'];
7790
$fileLength = strlen($file);

0 commit comments

Comments
 (0)