From e4b35751331e59c7721403841d7b3dbd70a0fb9b Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Sun, 29 Jun 2014 21:30:45 +0200 Subject: [PATCH] Ignore comments starting by '/*' --- PHP/CodeCoverage/Util.php | 27 ++++++++++++++------------- Tests/PHP/CodeCoverage/UtilTest.php | 3 +++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PHP/CodeCoverage/Util.php b/PHP/CodeCoverage/Util.php index 688afaee4..dc382f5a0 100644 --- a/PHP/CodeCoverage/Util.php +++ b/PHP/CodeCoverage/Util.php @@ -134,23 +134,24 @@ public static function getLinesToBeIgnored($filename, $cacheTokens = TRUE) $stop = TRUE; } - // be sure the comment doesn't have some token BEFORE it on the same line... - // it would not be safe to ignore the whole line in those cases. - if (0 === strpos($_token, $_line)) { - $count = substr_count($token, "\n"); - $line = $token->getLine(); + if (!$ignore) { + $start = $token->getLine(); + $end = $start + substr_count($token, "\n"); + + // Do not ignore the first line when there is a token + // before the comment + if (0 !== strpos($_token, $_line)) { + $start++; + } - for ($i = $line; $i < $line + $count; $i++) { + for ($i = $start; $i < $end; $i++) { self::$ignoredLines[$filename][$i] = TRUE; } - if ($token instanceof PHP_Token_DOC_COMMENT) { - // Workaround for the fact the DOC_COMMENT token - // does not include the final \n character in its - // text. - if (substr(trim($lines[$i-1]), -2) == '*/') { - self::$ignoredLines[$filename][$i] = TRUE; - } + // A DOC_COMMENT token or a COMMENT token starting with "/*" + // does not contain the final \n character in its text + if (0 === strpos($_token, '/*') && '*/' === substr(trim($lines[$i-1]), -2)) { + self::$ignoredLines[$filename][$i] = TRUE; } } } diff --git a/Tests/PHP/CodeCoverage/UtilTest.php b/Tests/PHP/CodeCoverage/UtilTest.php index d1cc8c289..25c3d6e51 100644 --- a/Tests/PHP/CodeCoverage/UtilTest.php +++ b/Tests/PHP/CodeCoverage/UtilTest.php @@ -201,8 +201,11 @@ public function testGetLinesToBeIgnoredOneLineAnnotations() 14 => TRUE, 17 => TRUE, 19 => TRUE, + 20 => TRUE, 22 => TRUE, 23 => TRUE, + 24 => TRUE, + 26 => TRUE, 27 => TRUE, 28 => TRUE, 29 => TRUE,