From db75bb53535395ec598e72d4b92ddaad08755b86 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 14 Sep 2015 15:43:57 +1000 Subject: [PATCH] Fixed bug #694 : Long sniff codes can cause PHP warnings in source report when showing error codes --- CodeSniffer/Reports/Source.php | 18 ++++++++++++++---- package.xml | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CodeSniffer/Reports/Source.php b/CodeSniffer/Reports/Source.php index 35bab665c2..eaa15225e9 100644 --- a/CodeSniffer/Reports/Source.php +++ b/CodeSniffer/Reports/Source.php @@ -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) { @@ -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))); @@ -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) { diff --git a/package.xml b/package.xml index 5c73f0a997..886adf1b16 100644 --- a/package.xml +++ b/package.xml @@ -28,6 +28,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - 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