Skip to content

Commit bd67246

Browse files
committed
Merge branch 'feature/report-full-fix-message-with-linebreaks' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 8e2b570 + 4a46c83 commit bd67246

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/Reports/Full.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,40 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
114114

115115
// The maximum amount of space an error message can use.
116116
$maxErrorSpace = ($width - $paddingLength - 1);
117-
if ($showSources === true) {
118-
// Account for the chars used to print colors.
119-
$maxErrorSpace += 8;
120-
}
121117

122118
foreach ($report['messages'] as $line => $lineErrors) {
123119
foreach ($lineErrors as $column => $colErrors) {
124120
foreach ($colErrors as $error) {
125-
$message = $error['message'];
126-
$message = str_replace("\n", "\n".$paddingLine2, $message);
127-
if ($showSources === true) {
128-
$message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
121+
$message = $error['message'];
122+
$msgLines = [$message];
123+
if (strpos($message, "\n") !== false) {
124+
$msgLines = explode("\n", $message);
125+
}
126+
127+
$errorMsg = '';
128+
$lastLine = (count($msgLines) - 1);
129+
foreach ($msgLines as $k => $msgLine) {
130+
if ($k === 0) {
131+
if ($showSources === true) {
132+
$errorMsg .= "\033[1m";
133+
}
134+
} else {
135+
$errorMsg .= PHP_EOL.$paddingLine2;
136+
}
137+
138+
if ($k === $lastLine && $showSources === true) {
139+
$msgLine .= "\033[0m".' ('.$error['source'].')';
140+
}
141+
142+
$errorMsg .= wordwrap(
143+
$msgLine,
144+
$maxErrorSpace,
145+
PHP_EOL.$paddingLine2
146+
);
129147
}
130148

131149
// The padding that goes on the front of the line.
132-
$padding = ($maxLineNumLength - strlen($line));
133-
$errorMsg = wordwrap(
134-
$message,
135-
$maxErrorSpace,
136-
PHP_EOL.$paddingLine2
137-
);
150+
$padding = ($maxLineNumLength - strlen($line));
138151

139152
echo ' '.str_repeat(' ', $padding).$line.' | ';
140153
if ($error['type'] === 'ERROR') {

0 commit comments

Comments
 (0)