Skip to content

Commit 11f0bac

Browse files
authored
Merge pull request #154 from PHPCSStandards/feature/report-full-delimiter-bug
Report Full: fix delimiter line bug
2 parents 18cb0d4 + dff4c58 commit 11f0bac

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Reports/Full.php

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

7285
$maxErrorLength = max($maxErrorLength, ($length + 1));
73-
}
74-
}
75-
}
86+
}//end foreach
87+
}//end foreach
88+
}//end foreach
7689

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

0 commit comments

Comments
 (0)