Skip to content

Commit db75bb5

Browse files
committed
Fixed bug #694 : Long sniff codes can cause PHP warnings in source report when showing error codes
1 parent d187215 commit db75bb5

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CodeSniffer/Reports/Source.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,15 @@ public function generate(
177177
echo "\033[0m".str_repeat('-', $width).PHP_EOL;
178178

179179
$fixableSources = 0;
180-
$maxSniffWidth = 37;
180+
181+
if ($showSources === true) {
182+
$maxSniffWidth = ($width - 7);
183+
} else {
184+
$maxSniffWidth = ($width - 37);
185+
}
186+
181187
if ($totalFixable > 0) {
182-
$maxSniffWidth += 4;
188+
$maxSniffWidth -= 4;
183189
}
184190

185191
foreach ($this->_sourceCache as $source => $sourceData) {
@@ -196,6 +202,10 @@ public function generate(
196202
}
197203

198204
if ($showSources === true) {
205+
if ($sourceData['strlen'] > $maxSniffWidth) {
206+
$source = substr($source, 0, $maxSniffWidth);
207+
}
208+
199209
echo $source;
200210
if ($totalFixable > 0) {
201211
echo str_repeat(' ', ($width - 9 - strlen($source)));
@@ -219,8 +229,8 @@ public function generate(
219229
echo $category.str_repeat(' ', (20 - strlen($category)));
220230

221231
$sniff = $parts[2];
222-
if (strlen($sniff) > ($width - $maxSniffWidth)) {
223-
$sniff = substr($sniff, 0, ($width - $maxSniffWidth - strlen($sniff)));
232+
if (strlen($sniff) > $maxSniffWidth) {
233+
$sniff = substr($sniff, 0, $maxSniffWidth);
224234
}
225235

226236
if ($totalFixable > 0) {

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2828
<notes>
2929
- Fixed bug #625 : Consider working around T_HASHBANG in HHVM 3.5.x and 3.6.x
3030
-- Thanks to Kunal Mehta for the patch
31+
- Fixed bug #694 : Long sniff codes can cause PHP warnings in source report when showing error codes
3132
</notes>
3233
<contents>
3334
<dir name="/">

0 commit comments

Comments
 (0)