Skip to content

Commit

Permalink
Fixed bug squizlabs#694 : Long sniff codes can cause PHP warnings in …
Browse files Browse the repository at this point in the history
…source report when showing error codes
  • Loading branch information
gsherwood committed Sep 14, 2015
1 parent d187215 commit db75bb5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions CodeSniffer/Reports/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,15 @@ public function generate(
echo "\033[0m".str_repeat('-', $width).PHP_EOL;

$fixableSources = 0;
$maxSniffWidth = 37;

if ($showSources === true) {
$maxSniffWidth = ($width - 7);
} else {
$maxSniffWidth = ($width - 37);
}

if ($totalFixable > 0) {
$maxSniffWidth += 4;
$maxSniffWidth -= 4;
}

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

if ($showSources === true) {
if ($sourceData['strlen'] > $maxSniffWidth) {
$source = substr($source, 0, $maxSniffWidth);
}

echo $source;
if ($totalFixable > 0) {
echo str_repeat(' ', ($width - 9 - strlen($source)));
Expand All @@ -219,8 +229,8 @@ public function generate(
echo $category.str_repeat(' ', (20 - strlen($category)));

$sniff = $parts[2];
if (strlen($sniff) > ($width - $maxSniffWidth)) {
$sniff = substr($sniff, 0, ($width - $maxSniffWidth - strlen($sniff)));
if (strlen($sniff) > $maxSniffWidth) {
$sniff = substr($sniff, 0, $maxSniffWidth);
}

if ($totalFixable > 0) {
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<notes>
- Fixed bug #625 : Consider working around T_HASHBANG in HHVM 3.5.x and 3.6.x
-- Thanks to Kunal Mehta for the patch
- Fixed bug #694 : Long sniff codes can cause PHP warnings in source report when showing error codes
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit db75bb5

Please sign in to comment.